我的代码
from bs4 import BeautifulSoup
with open('/Users/Mo1iy/Downloads/Plan-for-combating-master/week1/1_2/1_2answer_of_homework/1_2_homework_required/index.html','r') as wb_date:
Soup = BeautifulSoup(wb_date,'lxml')
images = Soup.select('body > div > div > div.col-md-9 > div > div > div > img')
prices = Soup.select('body > div > div > div.col-md-9 > div > div > div > div.caption > h4.pull-right')
titles = Soup.select('body > div > div > div.col-md-9 > div > div > div > div.caption > h4 > a')
pinfenliangs = Soup.select('body > div > div > div.col-md-9 > div > div > div > div.ratings > p.pull-right')
xingjis = Soup.select('body > div > div > div.col-md-9 > div > div > div > div.ratings > p:nth-of-type(2)')
# print(images,prices,titles,pinfenliang,xingji,sep= '\n----------------\n')
for image,price,title,pinfenliang,xingji in zip(images,prices,titles,pinfenliangs,xingjis):
data = {
'image':image.get('src'),
'price':price.get_text(),
'title':title.get_text(),
'pinfenliang':pinfenliang.get_text(),
'xinji':len(xingji.find_all("span" ,class_='glyphicon glyphicon-star')) }
print(data)