首页 > 解决方案 > python3.6 aiohttp响应时间和大小

问题描述

使用 python3.6 aiohttp 有一种方法可以获取我在发出请求时使用 pycurl 获取的所有以下统计信息。

name_lookup_time = curl_handle.getinfo(pycurl.NAMELOOKUP_TIME)
connect_time = curl_handle.getinfo(pycurl.CONNECT_TIME)
app_connect_time = curl_handle.getinfo(pycurl.APPCONNECT_TIME)
pre_transfer_time = curl_handle.getinfo(pycurl.PRETRANSFER_TIME)
start_transfer_time = curl_handle.getinfo(pycurl.STARTTRANSFER_TIME)
total_time = curl_handle.getinfo(pycurl.TOTAL_TIME)
redirect_time = curl_handle.getinfo(pycurl.REDIRECT_TIME)
redirect_cnt = curl_handle.getinfo(pycurl.REDIRECT_COUNT)
total_size = curl_handle.getinfo(pycurl.SIZE_DOWNLOAD)

目前我在我的爬虫中使用 pycurl 多实现来发出请求,然后我有代码收集每个请求的详细数据。替换 pycurl 并学习新东西。我有兴趣用 aiohttp 客户端实现替换发出请求的 pycurl 多代码。

阅读 aiohttp(https://aiohttp.readthedocs.io/en/stable/client_reference.html#aiohttp.ClientResponse)文档,我发现可以通过查看和计算作为 ClientResponse 对象一部分的历史序列来获得 redirect_cnt .

history
A Sequence of ClientResponse objects of preceding requests (earliest request first) if there were redirects, an empty sequence otherwise.

我可以不用大部分详细的时间数据。但是,我想收集 total_time 和 total_size 来满足我的最低要求。

标签: pythonpython-3.xpython-asyncioaiohttp

解决方案


推荐阅读