【发布时间】:2016-09-20 17:51:06
【问题描述】:
我是新的网络抓取,并试图抓取餐厅详细信息表单的所有内容,以便我可以继续进行进一步的抓取。
import requests
from bs4 import BeautifulSoup
import urllib
url = "https://www.foodpanda.in/restaurants"
r=requests.get(url)
soup=BeautifulSoup(r.content,"html.parser")
print(soup.find_all("Section",class_="js-infscroll-load-more-here")[0])
【问题讨论】:
-
问题是什么?
-
我收到 IndexError: list index out of range as error
-
通过回溯发布您对问题的完整解释。如果您收到该错误,则意味着
soup.find_all("Section",class_="js-infscroll-load-more-here")是一个空列表。 -
你能发布整个错误信息吗?我怀疑问题出在 findall(...)[0] 语句中。如果 findall 返回一个空列表,那么您对索引 0 的调用超出了范围。
-
尝试获取餐厅表单的所有内容,但我在 Traceback 中遇到错误(最近一次调用最后一次):文件“C:\Users\aenis\Desktop\zomotaScript.py”,第 7 行,在
print(soup.find_all("Section",class_="js-infscroll-load-more-here")[0]) IndexError: list index out of range [Finished in 6.2s]
标签: python web-scraping beautifulsoup