python爬虫添加请求头代码实例

python爬虫添加请求头代码实例[Python基础]

这篇文章主要介绍了python爬虫添加请求头代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

 

request  

 

import requests
headers = {
  # "Accept": "application/json, text/javascript, */*; q=0.01",
  # "Accept": "*/*",
  # "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7",
  # "Cache-Control": "no-cache",
  # "accept-encoding": "gzip, deflate, br",
  "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
  "Referer": "https://www.google.com/"
}

resp = requests.get("http://httpbin.org/get", headers=headers)
print(resp.content)
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python爬虫添加请求头代码实例