码迷,mamicode.com
首页 > 其他好文 > 详细

爬虫练习

时间:2017-01-19 16:13:08      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:port   select   div   rate   content   tle   练习   desc   data   

from bs4 import BeautifulSoup

info = []
with open(‘D:\web1111/new_index.html‘,‘r‘) as wb_data:
Soup = BeautifulSoup(wb_data,‘lxml‘)
images = Soup.select(‘body > div.main-content > ul > li > img‘)
titles = Soup.select(‘body > div.main-content > ul > li > div.article-info > h3 > a‘)
descs = Soup.select(‘body > div.main-content > ul > li > div.article-info > p.description‘)
rates = Soup.select(‘body > div.main-content > ul > li > div.rate > span‘)
cates = Soup.select(‘body > div.main-content > ul > li > div.article-info > p.meta-info‘)
# print (images,titles,descs,rates,cates)

for title,image,desc,rate,cate in zip(titles,images,descs,rates,cates):
data = {
‘title‘ :title.get_text(),
‘rate‘ :rate.get_text(),
‘desc‘ :desc.get_text(),
‘cate‘ :list(cate.stripped_strings),
‘image‘ :image.get(‘src‘)
}
info.append(data)


for i in info:
if float(i[‘rate‘])>3:
print(i[‘title‘],i[‘cate‘])

‘‘‘
body > div.main-content > ul > li:nth-child(1) > div.article-info > h3 > a
body > div.main-content > ul > li:nth-child(1) > div.article-info > p.meta-info > span:nth-child(2)
body > div.main-content > ul > li:nth-child(1) > div.rate > span
body > div.main-content > ul > li:nth-child(1) > div.article-info > p.description
body > div.main-content > ul > li:nth-child(1) > img
‘‘‘

爬虫练习

标签:port   select   div   rate   content   tle   练习   desc   data   

原文地址:http://www.cnblogs.com/tangbinghaochi/p/6307003.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!