Python 爬取简单网页
生活随笔
收集整理的這篇文章主要介紹了
Python 爬取简单网页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 import urllib.request
2 url = "http://www.baidu.com/s?wd=" #get網址格式:“https://www.baidu.com/s?wd=關鍵字”
3 key="周杰倫"
4 key_code=urllib.request.quote(key) # 漢字編碼轉化
5 url_all=url+key_code
6 req=urllib.request.Request(url_all)
7 data=urllib.request.urlopen(req).read()
8
9 fhandle = open("F:/Python/5.html","wb") #把爬取到的數據,寫入指定文件夾,并生成文件
10 fhandle.write(data)
11 fhandle.close()
?
轉載于:https://www.cnblogs.com/Hunter-541695/p/9534619.html
總結
以上是生活随笔為你收集整理的Python 爬取简单网页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue-music(1)音乐播发器 项目
- 下一篇: Python - - 项目实战 -- p