python3.4 百度贴吧小爬虫
生活随笔
收集整理的這篇文章主要介紹了
python3.4 百度贴吧小爬虫
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import string,urllib.request
def cookie(get_page,begin,end):for i in range(begin,end+1):sname = 'f:/test/' + '網頁' + str(i).zfill(3) + '.html'print ('正在下載第' + str(i) + '個頁面...')m = urllib.request.urlopen(get_page+str(i)).read().decode('gbk')with open(sname,'w+') as file:file.write(m)
get_page = str(input('請輸入貼吧的地址,去掉pn=后面的數字:\n'))
begin = int(input('請輸入開始的頁數:\n'))
end = int(input('請輸入終點的頁數:\n'))
#調用
cookie(get_page,begin,end)
一個問題,保存下來的網頁要用?
m = urllib.request.urlopen(get_page+str(i)).read().decode('gbk')這樣加上 .decode('gbk') 之后才能保存,否則打開文字全部都是亂碼
抓取網頁到本地,參考博客 ?網絡爬蟲(六):一個簡單的百度貼吧的小爬蟲
總結
以上是生活随笔為你收集整理的python3.4 百度贴吧小爬虫的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件工程专业期末项目开发全流程模拟日志《
- 下一篇: 利用vsocde构建Python-Fla