"""quote: 进行URL编码,发送中文请求""" | |
from urllib.request import urlopen,Request | |
from fake_useragent import UserAgent | |
from urllib.parse import quote | |
url = f'https://www.amap.com' | |
# 随机生成用户代理 | |
ua = UserAgent() | |
headers = { | |
'User-Agent':ua.chrome | |
} | |
# 创建 request对象 | |
req = Request(url,headers = headers) | |
# 发送请求 | |
resp = urlopen(req) | |
with open("./gaode.html", 'w') as f: | |
f.write(resp.read().decode()) |