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)
相关推荐
wan9yu14 小时前
为什么你需要给 LLM 的数据"加密"而不是"脱敏"?我写了一个开源工具
python
清风徐来QCQ14 小时前
八股文(1)
java·开发语言
lsx20240614 小时前
网站主机技术
开发语言
摇滚侠14 小时前
你是一名 java 程序员,总结定义数组的方式
java·开发语言·python
xyq202415 小时前
Vue3 条件语句详解
开发语言
这个名有人用不15 小时前
解决 uv 虚拟环境使用 pip 命令提示command not found的办法
python·pip·uv·claude code
浩浩kids15 小时前
R•Homework
开发语言·r语言
Oueii15 小时前
掌握Python魔法方法(Magic Methods)
jvm·数据库·python
qq_4160187215 小时前
设计模式在C++中的实现
开发语言·c++·算法