【问题标题】:How to scrape lists into a list pandas如何将列表刮成列表熊猫
【发布时间】:2019-01-17 09:12:01
【问题描述】:

我想遍历循环并输出一个列表列表,但我一直收到的错误是“列表索引超出范围”或“'list' 对象不能解释为整数”

#BEGIN LOOP SCRAPE
studentIDs=[1,2,3]
for i, val in  enumerate(studentIDs):

    #Begin scraping
    out_data=[pd.read_html(browser.page_source)]
    #Clicking to another student webpage
    browser.find_element_by_xpath('returns to another page that needs to be scraped').click()

【问题讨论】:

  • 您需要包含错误所在的行。似乎我们看到了部分代码
  • 当它循环时,在第二次复飞时,它不会刮掉并且发生错误。错误是“'list' 对象不能解释为整数”
  • 是的,哪一行代码准确地引发了该错误?我认为这是您删除的第一条评论中的评论
  • 不,错误发生在第二次循环的“out_data=[pd.read_html(browser.page_source)]”上。

标签: python list pandas loops web-scraping


【解决方案1】:
studentIDs=[1,2,3]
for index in range(len(studentIDs)):
 out_data=out_data+[pd.read_html(browser.page_source)]

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 2017-09-17
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    相关资源
    最近更新 更多