開始學習 python 爬蟲
第一個獲取使用最多的網站-百度 源代碼? 并將源代碼保存到文件中
from urllib.request import urlopenurl = 'https://www.baidu.com'
resp = urlopen(url)with open('baidu.html', 'w', encoding='utf-8') as f:f.write(resp.read().decode('utf-8'))
知識點:
1. urlopen? 打開網址
2. with open 文件操作
3. decode 解碼
運行結果: