我是新的网络抓取,并试图抓取所有内容的餐厅的详细信息形式,以便我可以继续我的进一步抓取。
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])发布于 2016-09-21 02:55:24
问题出在为soup.find_all("Section",class_="js-infscroll-load-more-here")访问索引0处的元素时,因为结果是一个空列表。
发布于 2016-09-21 08:05:38
html没有大写标签的概念,即使在源代码本身,它也是section,而不是带有小写s的Section:
section = soup.find_all("section",class_="js-infscroll-load-more-here")[0]因为只有一个,所以你也可以使用find:
section = soup.find("section",class_="js-infscroll-load-more-here")这两个都会找到你正在寻找的东西。
https://stackoverflow.com/questions/39600662
复制相似问题