【发布时间】:2020-08-21 02:36:52
【问题描述】:
df_results = pd.DataFrame()
#testing with the for loop instead of while because I don't want to run all pges yet, just first 4
for i in range(0,5):
element = driver.find_element_by_xpath("//span[@class= 'next fg-button ui-state-default']")
ActionChains(driver).move_to_element(element).click().perform()
# I've also tried by removing the variable
df_results = df_results.append(pd.read_html(driver.page_source))
df1 = pd.concat([df_results])
#save as csv
df1.to_csv('cds.csv')
我正在尝试通过每个页面中具有相同元素的 1 个表格来抓取多个页面。 (当我写这个时听起来很简单......) 我只是试图将每个页面保存到一个空的数据框。 '''df_results''' 仅从最后一页获取表格行,并且显示相同的行 5 次。所以它成功地浏览了每一页,但没有保存每一行。 我尝试在循环中追加,然后在循环外添加 concat 但它不起作用。
【问题讨论】:
-
添加 URL 以及从哪里抓取数据。
-
@Vin 这不是我想公开的事情,但我能够解决它。还是谢谢!
标签: python-3.x pandas selenium dataframe web-scraping