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
时间: 2024-10-10 23:50:45