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)
相关推荐
没有医保李先生几秒前
字节对齐的总结
java·开发语言
Elastic 中国社区官方博客21 分钟前
使用 Elastic 进行网络监控:统一网络可观测性
大数据·开发语言·网络·人工智能·elasticsearch·搜索引擎·全文检索
Codefengfeng24 分钟前
Python Base环境中加包的方法
开发语言·python
清水白石00825 分钟前
《Python 编程全景解析:从核心精要到测试替身(Test Doubles)五大武器的实战淬炼》
开发语言·python
如若1231 小时前
AutoDL云服务器 NVIDIA 570驱动 EGL渲染修复全记录
运维·服务器·python
甲枫叶1 小时前
【claude】Claude Code正式引入Git Worktree原生支持:Agent全面实现并行独立工作
java·人工智能·git·python·ai编程
六件套是我2 小时前
无法访问org.springframeword.beans.factory.annotation.Value
java·开发语言·spring boot
S-码农2 小时前
Linux ——条件变量
linux·开发语言
清水白石0082 小时前
《Python 编程全景解析:从核心精要到 Hypothesis 属性基测试的边界探索》
开发语言·python