requests的基本使用

首先需要导入模块

import requests

携带get请求方式

params = {
'xxx': 'yyy',
}
res = requests.get('xxx',params=params)
print(res.text) # 打印响应体内容

携带请求头

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'
}
requests.get('xxx',headers=headers)

post请求携带data

data = {
'xxx': 'yyy'
}
requests.get('xxx',data=data)
# data参数:urlencoded
requests.post('地址',data=b'name=xxx&age=19')
# json编码:json
requests.post('地址',json={'name':'xxx','age':19})

携带cookie

cookie = {
'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJjZHVfNTMyMDcwNzg0NjAiLCJleHBpcmUiOiIxNzEwOTAxOTY5NTM2In0.eseWTCMqp-yHa7rWgSvPhnWVhhQAgqGIvIgLGbvcBcc'
}
requests.post('xxx',cookies=cookie)

posted @   wellplayed  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示