好友
阅读权限10
听众
最后登录1970-1-1
|
50吾爱币
本帖最后由 jin920619 于 2022-5-24 23:51 编辑
学了一下POST,打算并发和循环POST,运行了一下发现太慢了,基本上2秒后接收返回数据后再循环,如何才能实现可以设置并发速度
import requests
while True:
headers1 = {
}
json_data1 = {
}
headers2 = {
}
json_data2 = {
}
headers3 = {
}
json_data3 = {
}
headers4 = {
}
json_data4 = {
}
headers5 = {
}
json_data5 = {
}
headers6 = {
}
json_data6 = {
}
headers7 = {
}
json_data7 = {
}
headers8 = {
}
json_data8 = {
}
headers9 = {
}
json_data9 = {
}
response1 = requests.post('1', headers=headers1, json=json_data1)
response2 = requests.post('1', headers=headers2, json=json_data2)
response3 = requests.post('1', headers=headers3, json=json_data3)
response4 = requests.post('1', headers=headers4, json=json_data4)
response5 = requests.post('1', headers=headers5, json=json_data5)
response6 = requests.post('1', headers=headers6, json=json_data6)
response7 = requests.post('1', headers=headers7, json=json_data7)
response8 = requests.post('1', headers=headers8, json=json_data8)
response9 = requests.post('1', headers=headers9, json=json_data9)
print(response1.text)
print(response2.text)
print(response3.text)
print(response4.text)
print(response5.text)
print(response6.text)
print(response7.text)
print(response8.text)
print(response9.text) |
最佳答案
查看完整内容
[mw_shl_code=python,true]import asyncio
import aiohttp
CONCURRENCY = 5
URL = 'https://www.baidu.com'
JSON_DATA = {
}
HEADERS = {
}
semaphore = asyncio.Semaphore(CONCURRENCY)
async def fetch():
async with semaphore:
async with aiohttp.ClientSession() as session:
async with session.post(URL, headers=HEADERS, json=JSON_DATA) as response:
...
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|