我剛學(xué)python不久,參考 靜覓博客http://cuiqingcai.com/1052.html寫的這個(gè)爬蟲
我沒用正則表達(dá)式,用了beautifulsoup
代碼比較簡(jiǎn)易
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