Scraping a website with content added via javascript with Selenium in Python -
I am trying to scrape data from a website using selenium and phatomaj in Python. However, this website is adding the data I am interested in via javascript. Is there a way to wait for data before withdrawing selenium? So far, we have tried:
importExport import webdriver as selenium.webdriver UI as phonomicon.webdriver.support.ui phantomjs = '/ usr / local / bin / Phantomjs' url = '[Redacted]' with contextlib.closing (webdriver.PhantomJS (phantomjs)) as driver: driver.get (url) wait = ui.WebDriverWait (driver, 10) wait.until (lambda driver : Driver.execute_script ("return document" ("[Redacted] ')) driver.execute_script (" return document.getElementById (\ "myID \") .intermentById (\ "myID \") .interTextById (\ "myID \") .interText ")
Unfortunately, this code raises selenium.common.exceptions.TimeoutException: message: none
why We are unable to change the contents of the id
.
We are using PhantmJs 1.9.7, Python 2.7.5 and Virtual and Selenium 2.41.0. The correct way to do or we have forgotten something
edit
@ExperimentsWithCode after following the comment, we have tried to load the content To: looping: driver
with referencelib.closing (webdriver.PhantomJS (phantomjs)) as driver: driver.get (url) wait = ui.WebDriverWait (driver, 10) found = found Not gone: try : Wait.until (Lambda driver: driver.execute_script ("return document.getElementById (\" myID \ "). InnerText ") foundwith ('[redacted]')) driver.execute_script (" Return Document.getElementById (\ "myID \"). InnerText =) found = Also true: print "not found" near
< / Pre>
Comments
Post a Comment