# 浏览器伪装 import urllib.request url = "https://blog.csdn.net/weixin_42760923" res = urllib.request.urlopen(url).read().decode("utf-8") # 头文件格式header=("User-Agent","具体用户代理值") headers = ("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36") opener = urllib.request.build_opener() data = opener.open(url).read() with open("../伪装浏览器.html", "wb") as f: f.write(data)