我正在关注在线教程,以使用python抓取数据。但是我只在最后一个容器中得到结果吗?例如,该站点在12个容器下列出了12种不同的产品,而我的代码仅返回了最后一个容器中的数据,而不是全部12个。
非常感谢您的帮助。
谢谢 亚历克斯
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.newegg.com/global/nz-en/Laptops-Notebooks/SubCategory/ID-32?Tid=1567456'
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"})
for container in containers:
brand_description = container.a.img["title"]
price_box = container.findAll("li",{"class":"price-current"})
price = price_box[0].strong.text
print("brand_description:" + brand_description)
print("price:" + price)