美文网首页
实战计划:爬取网页信息

实战计划:爬取网页信息

作者: Mo1iy | 来源:发表于2016-06-15 06:54 被阅读0次

我的代码

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)

相关文章

网友评论

      本文标题:实战计划:爬取网页信息

      本文链接:https://www.haomeiwen.com/subject/qjnudttx.html