Помогите пожалуйста.У меня TypeError ниже:
Traceback (most recent call last):
File "my_first_webscrape.py", line 22, in <module>
brand_name = brand[0].img["title"]
TypeError: 'NoneType' object is not subscriptable
Вот мой код:
import bs4
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.newegg.com/global/ph-en/Laptops-Notebooks/SubCategory/ID-32?Tid=702226'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("div",{"class":"item-container"})
container = containers[0]
for container in containers:
brand = container.findAll("div", {"class":"item-branding"})
brand_name = brand[0].img["title"]
title = container.findAll("a", {"class":"item-title"})
title_name = title[0].text
price = container.findAll("li", {"class":"price-current"})
price_current = price[0].strong.text
print("brand_name: " + brand_name)
print("title_name: " + title_name)
print("price_current: " + price_current)
=====================================================
Я думаю, что ошибка происходит из-за возвращения brand_name None, но я не знаю, какпочини это.