热门搜索 :
考研考公
您的当前位置:首页正文

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

来源:东饰资讯网

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

代码比较简易

import urllib2
from bs4 import BeautifulSoup

 url = 

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
Top