D80【 python 接口自动化学习】- python基础之HTTP
day80 requests请求加入headers
学习日期:20241126
学习目标:http定义及实战 -- requests请求加入headers
学习笔记:
requests请求加入headers
import requests
url='https://movie.douban.com/j/search_subjects'
params={"type":"movie","tag":"热门","page_limit":"50","page_start":"0"}
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"}
r=requests.get(url=url,params=params,headers=headers)
print(r.status_code) # 200
print(r.json()) # {'subjects': [{'episodes_info': '', 'rate': '8.9', 'cover_x': 5904...
总结
- request请求中headers存放请求头信息