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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -