标签:url head webkit get import safari htm gen http
from urllib.request import *
# 设置头信息,两种方法
# 1.直接在request中填入参数
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36"}
request = Request("此处填写Url(必须以http或https开头)", headers=header )
# 2.设置header
request = Request(url)
request.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36")
request.get_header("User-Agent") # 获取User-Agent
标签:url head webkit get import safari htm gen http
原文地址:https://www.cnblogs.com/peilanluo/p/10229370.html