📜  为什么在请求库中提到用户代理 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:24.505000             🧑  作者: Mango

代码示例2
#If you are using python requests old version 

import requests

url = 'SOME URL'

# Get a copy of the default headers that requests would use
headers = requests.utils.default_headers()

# Update the headers with your custom ones
# You don't have to worry about case-sensitivity with
# the dictionary keys, because default_headers uses a custom
# CaseInsensitiveDict implementation within requests' source code.
headers.update(
    {
        'User-Agent': 'My User Agent 1.0',
    }
)

response = requests.get(url, headers=headers)