简易爬虫抓取糗事百科热门

我刚学python不久,参考 静觅博客http://cuiqingcai.com/1052.html写的这个爬虫

我没用正则表达式,用了beautifulsoup

代码比较简易

import urllib2
from bs4 import BeautifulSoup

 url = 'http://www.qiushibaike.com/hot/'

user_agent = 'Mozilla/5.0 (Windows NT 6.1)'

headers = {'User-agent' : user_agent}

request = urllib2.Request(url,headers= headers)

response = urllib2.urlopen(request)

cat_img = response.read().decode('utf-8')

bs0bj = BeautifulSoup(cat_img,"html.parser")

namelist = bs0bj.findAll('div', "content")

for name in namelist:

print(name.string)

《简易爬虫抓取糗事百科热门》 QQ截图20160727202440.png

    原文作者:LEONYao
    原文地址: https://www.jianshu.com/p/e692af421799
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞