找到自己的计算机的useragent字段并贴出来方法伪装浏览器需要自定义请求报头也就是在发送Request请求时加入特定的

1、找到自己的计算机的useragent字段,并贴出来方法。 伪装浏览器需要自定义请求报头,也就是在发送Request请求时,加入特定的Headers user_agent = {“User-Agent” : “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT6.1; Trident/5.0)”} request = urllib.request.Request(url, headers = user_agent) request.add_header(“Connection”, “keep-alive”)

import requests
url = "https://www.jd.com/"
headers = {
    'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    'accept-encoding': "gzip, deflate, br",
    'accept-language': "zh-CN,zh;q=0.9",
    'cache-control': "no-cache",
    'connection': "keep-alive",
    'host': "www.jd.com",
    'sec-fetch-dest': "document",
    'sec-fetch-mode': "navigate",
    'sec-fetch-site': "cross-site",
    'sec-fetch-user': "?1",
    'upgrade-insecure-requests': "1",
    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
    'postman-token': "abf3d153-9988-c8d3-166c-6313df60ef61"
    }
response = requests.request("GET", url, headers=headers)
print(response.text)

找到自己的计算机的useragent字段并贴出来方法伪装浏览器需要自定义请求报头也就是在发送Request请求时加入特定的_第1张图片

你可能感兴趣的:(python(学校)作业)