extracting links with a specific class with Selenium in Python -
i trying extract links infinite scroll website
it's code scrolling down page
driver = webdriver.chrome('c:\\program files (x86)\\google\\chrome\\chromedriver.exe') driver.get('http://seekingalpha.com/market-news/top-news') in range(0,2): driver.implicitly_wait(15) driver.execute_script("window.scrollto(0, document.body.scrollheight);") time.sleep(20)
i aim @ extracting specific links page. class = "market_current_title" , html following :
<a class="market_current_title" href="/news/3223955-dow-wraps-best-week-since-2011-s-and-p-strongest-week-since-2014" sasource="titles_mc_top_news" target="_self">dow wraps best week since 2011; s&p in strongest week since 2014</a>
when used
url = driver.find_elements_by_class_name('market_current_title')
i ended error says "stale element reference: element not attached page document". tried
url = driver.find_elements_by_xpath("//div[@id='a']//a[@class='market_current_title']")
but says there no such link !!! have idea solving problem?
you're trying interact element changed (probably elements above scrolling , off screen). try this answer options on how overcome this.
here's snippet:
from selenium.common.exceptions import timeoutexception selenium.webdriver.common.by import import selenium.webdriver.support.expected_conditions ec import selenium.webdriver.support.ui ui # return true if element visible within 2 seconds, otherwise false def is_visible(self, locator, timeout=2): try: ui.webdriverwait(driver, timeout).until(ec.visibility_of_element_located((by.css_selector, locator))) return true except timeoutexception: return false
Comments
Post a Comment