【发布时间】:2020-12-19 11:25:26
【问题描述】:
您好,我是网络抓取的新手,我正在尝试学习教程,但我在访问某些项目时遇到了问题!这是我要抓取的页面https://www.newegg.com/todays-deals?cm_sp=Homepage_4spots-_--_-12182020,我想获得产品的标题、品牌和价格,在循环之外一切正常!但我在为所有产品创建循环时出错
#this is the loop to scrape all items from the webpage
containers = pagesoup.findAll("div",{"class":"item-container"})
for con in containers:
title = con.img["title"]
titleco=con.findAll("div",{"class":"item-branding"})
brand= titleco[0].img["title"]
priceco=con.findAll("li",{"class":"price-current"})
priceco[0].text.strip()
我收到这个错误
----> 5 brand= titleco[0].img["title"] 'NoneType' 对象不可下标
【问题讨论】:
-
尝试只打印
titleco。我想你会发现它是空的。所以问题来自它上面的行,具体来说,.finall(...)调用没有返回任何内容。 -
不,在这个循环之外我得到了我需要刮的一切!
标签: python web-scraping beautifulsoup