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

我刚学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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容