【发布时间】:2021-01-05 15:52:03
【问题描述】:
所以我很期待对这个link中出现的表格进行抓取。
为了刮,我决定使用硒。
在我的第一次尝试中,我所做的是:
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
html_source = self.driver.page_source
self.driver.quit()
BeautifulSoup(html_source, "html5lib")
table = soup.find('table', {'class': 'heavy-table ncpulse-fav-table ncpulse-sortable compressed-table'})
df = pd.read_html(str(table), flavor='html5lib', header=0, thousands='.', decimal=',')
但是它输出错误
'no tables found'
然后我尝试使用 expected_conditions 类,因为当我在 SO 中查找时,可能“页面源甚至在子元素完全呈现之前就被拉出”
因此我尝试了这样的事情:
driver.get(route)
element_present = expected_conditions.presence_of_element_located(
(By.CLASS_NAME, 'heavy-table ncpulse-fav-table ncpulse-sortable compressed-table'))
WebDriverWait(driver, 20).until(element_present)
html_source = driver.page_source
driver.quit()
但是这次它输出:
selenium.common.exceptions.TimeoutException: Message
因此我的问题是:我怎样才能获得所需的输出?我在使用 expected_conditions 类时做错了什么?到底是什么问题/前端技术让刮桌子变得如此困难?
【问题讨论】:
标签: python selenium xpath css-selectors webdriverwait