python 爬虫 request get或post传参

爬虫传参

python 复制代码
import requests

url = 'http://www.xxx'

# get 或 post 传参数据
data = {
    "pageNo": 1652,
    "pageSize": 10,
}

headers = {
    'Cookie': '',
    'Host': '',
    'Origin': '',
    'Referer': '',
    'User-Agent': '',
}

# get 请求
# res = requests.get(
#     url,
#     params=data,
#     headers=headers,
# )

# post 请求
res = requests.post(
    url,
    data=data,
    headers=headers,
)

print(res.content.decode('utf-8'))

post 传参的请求可从浏览器复制字典粘贴。

header 请求头参数,提供如下工具脚本:

把请求头参数复制到content.txt 文件中

content.txt:

工具:

python 复制代码
# 假设txt文件内容如下
txt = open('content.txt').read()

# 使用splitlines()方法将txt内容分割为行,然后使用json.loads()方法将每一行转换为字典
lines = txt.splitlines()
data = [line.split(': ') for line in lines]
headers_dict = {k: v for k, v in data}

# 输出字典
print(headers_dict)
相关推荐
霍霍的袁几秒前
【C++】string类 从 入门使用 到 底层深浅拷贝模拟实现
开发语言·c++·visual studio
酷在前行7 分钟前
【R绘图】Nature Communications 半眼图复刻:分布、区间与多面板排版(保姆级教程)
android·开发语言·r语言
这个人懒得名字都没写14 分钟前
Flask + PyArmor Gunicorn启动报错:RuntimeError: unauthorised use of script
python·flask·gunicorn·pyarmor
C++、Java和Python的菜鸟19 分钟前
第10章 后端Web进阶(Maven高级)
开发语言·python
暗黑小白35 分钟前
路由策略与引擎可替换性
后端·python·ai agent
小罗水1 小时前
第 20 章 高级 RAG 技术与检索优化
人工智能·python·机器学习
神罚天下ET1 小时前
.NET 新增功能系列文章——C# 中的新增功能
开发语言·c#·.net
所愿ღ1 小时前
SSM框架-Spring3
java·开发语言·笔记·spring
bamb001 小时前
一个项目带你入门AI应用开发06
python
liwulin05061 小时前
【ESP32S3】调用百度云语音合成接口后重启
python