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)
相关推荐
曲幽5 小时前
FastAPI + PostgreSQL 实战:从入门到不踩坑,一次讲透
python·sql·postgresql·fastapi·web·postgres·db·asyncpg
用户83562907805110 小时前
使用 C# 在 Excel 中创建数据透视表
后端·python
码路飞13 小时前
FastMCP 实战:一个 .py 文件,给 Claude Code 装上 3 个超实用工具
python·ai编程·mcp
dev派15 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪16 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户03321266636716 小时前
将 PDF 文档转换为图片【Python 教程】
python
悟空爬虫18 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派18 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风20 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽1 天前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic