发送大量异步请求
Project description
aclient
安装说明
使用pip
或其他 PyPi 软件包进行安装
pip install aclient
使用 aclient 发送异步请求
您可以试试:
import re
from aclient import *
aclient = AsyncClient()
# 自定义解析函数 注意; 函数必需是异步的
async def parse(response, **kwargs):
text = await response.text()
# 测试: 获取 title 文本 - 百度一下
pattern = re.compile(f"<title>(.*?)</title>")
title = pattern.findall(text)[0]
return title
# 请求地址 可以发送大量地址
url = "https://www.baidu.com"
# urls列表格式
urls = [url for _ in range(2)]
result = aclient.get(urls, custom_parse=parse)
# 打印item数据
print(result)
# 结果
# result = {'0': '百度一下', '1': '百度一下'}
# urls字典格式
urls = {
f"第{i}个": {"url": url, "timeout": 5}
for i in range(2)
}
result = aclient.get(urls, custom_parse=parse)
# 打印item数据
print(result)
# 结果
# result = {'第0个': '百度一下', '第1个': '百度一下'}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aclient-1.0.7.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file aclient-1.0.7.tar.gz
.
File metadata
- Download URL: aclient-1.0.7.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d6c0bc3ec74868f20dba02fd557e22d37a63de688f3b1f95d9007cf0d2f9158 |
|
MD5 | e05f81fe9a547736f7d9d53e6b12d2ee |
|
BLAKE2b-256 | 603cbbc287192927921c7265b55d5095cba7c0e2a9e7dcad3de308c580257e1e |
File details
Details for the file aclient-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: aclient-1.0.7-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a00413e78e7162f89206392c65f35c445816e1faee1254b37b792f839529ee27 |
|
MD5 | b15e57709eafcbb380768f592a54b49e |
|
BLAKE2b-256 | 6a890078f29a9275844b7b0d0cdd170653f39af55611ff1f9d7192124e304b6c |