javascript - execute_script() doesn't work in python with selenium phantomjs -


from selenium import webdriver selenium.webdriver.support.ui import webdriverwait selenium.common.exceptions import nosuchelementexception selenium.webdriver.common.keys import keys bs4 import beautifulsoup  driver = webdriver.phantomjs() #driver = webdriver.firefox() driver.get('http://global.ahnlab.com/site/securitycenter/securityinsight/securityinsightlist.do') driver.execute_script("getview('2218')")  html_source = driver.page_source driver.quit()  soup = beautifulsoup(html_source)  print(soup.h1.string) 

when use firefox(), result [ahnlab puts in appearance @ rsaconference 4th straight year] want. when use phanthomjs(), result [security insight] don't want.

if use phantomjs(), can't result want? want first result using headless browser.

thanks.

the phantomjs driver not loading navigation after javascript call immediately. put sleep of 5-10 seconds after javascript call , should work you.

import time  selenium import webdriver selenium.webdriver.support.ui import webdriverwait selenium.common.exceptions import nosuchelementexception selenium.webdriver.common.keys import keys bs4 import beautifulsoup  driver = webdriver.phantomjs() #driver = webdriver.firefox() driver.get('http://global.ahnlab.com/site/securitycenter/securityinsight/securityinsightlist.do') driver.execute_script("getview('2218')")  # introduce sleep of 5 seconds here time.sleep(5)  html_source = driver.page_source driver.quit()  soup = beautifulsoup(html_source)  print(soup.h1.string) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -