I'm trying to scrape some data off of this site, and many other "wines" on this site, and am using selenium to do so as its a JS site. however, I'm finding that my code only sometimes works and other times it does not return any values even though nothing is changing.
I think I should use explicit waits with selenium to overcome this challenge, however I'm not sure how to integrate them, so any guidance on doing so would be helpful!
my code is
def ct_content(url):
browser = webdriver.PhantomJS()
browser.get(url)
wait = WebDriverWait(driver, 10)
html = browser.page_source
html = lxml.html.fromstring(html)
try:
content = html.xpath('//a[starts-with(@href, "list.asp?Table=List")]/text()')
browser.quit()
return content
except:
browser.quit()
return False
Thanks!