aclient
安装说明
使用pip
或其他 PyPi 软件包进行安装
pip install aclient
使用 aclient 发送异步请求
您可以试试:
import re
from aclient import *
aclient = AsyncClient()
async def parse(response, **kwargs):
text = await response.text()
pattern = re.compile(f"<title>(.*?)</title>")
title = pattern.findall(text)[0]
return title
url = "https://www.baidu.com"
urls = [url for _ in range(2)]
result = aclient.get(urls, custom_parse=parse)
print(result)
urls = {
f"第{i}个": {"url": url, "timeout": 5}
for i in range(2)
}
result = aclient.get(urls, custom_parse=parse)
print(result)