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 小时前
YOLO26-Seg ONNXruntime C++/python推理
开发语言·c++·python
YMWM_6 小时前
如何将包路径添加到conda环境lerobot的python路径中呢?
人工智能·python·conda
靓仔建6 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
田里的水稻6 小时前
ubuntu22.04_openclaw_ROS2
人工智能·python·机器人
IP搭子来一个6 小时前
爬虫IP地址受限怎么办?附解决方法
网络·爬虫·tcp/ip
梁正雄7 小时前
Python前端-2-css练习
前端·css·python
wefly20177 小时前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
赶路人儿7 小时前
UTC时间和时间戳介绍
java·开发语言
6+h7 小时前
【java】基本数据类型与包装类:拆箱装箱机制
java·开发语言·python
GDAL8 小时前
MANIFEST.in简介
linux·服务器·前端·python