【问题标题】:python crawling error: single positional indexer is out-of-boundspython爬取错误:单个位置索引器超出范围
【发布时间】:2019-01-11 14:42:15
【问题描述】:

我正在尝试从网站抓取数据并生成错误:单个位置索引器超出范围

代码如下:

 headurl="https://www.zoopla.co.uk/for-sale/details/"
 endurl="?search_identifier=733971d356a1970075aa7789ec8c815c"
 midrul=""
 for i in range(0,len(data),1):
 midurl= data.iloc[i,1]
 midurl=str(midurl)
 web=headurl+midurl+endurl
 text=requests.get(web)

 try:
     address=re.compile(r'display_address: "(.*?)",\n')
     mytext1=re.findall(address,text.text)
     data.iloc[i,3]=mytext1[0]
 except:
     data.iloc[i,3]="nodata"

mytext1 确实存在,因为当我使用 print() 时它会被一一打印出来

有人知道为什么会产生错误吗?

【问题讨论】:

    标签: python web-crawler


    【解决方案1】:

    错误出现在代码的except 部分,我相信您已通过错误消息确认。这个问题之前已经回答过了,这里:https://stackoverflow.com/a/37960827/7176819

    小贴士:

    • 在编写此类问题时包括回溯
    • 请缩进您的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2016-10-23
      • 2019-04-13
      • 2019-03-21
      相关资源
      最近更新 更多