url = ...
user_agent = ...
headers = {'User-Agent' : user_agent}
req = requests.request(url=url, headers=headers)

1. 构造 UA

# firefox 浏览器
user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:57.0) Gecko/20100101 Firefox/57.0'
# chrome 浏览器
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
posted on 2018-01-03 21:38  未雨愁眸  阅读(691)  评论(0编辑  收藏  举报