崎Response的响应带宽

时间:2020-08-08 17:39:31

标签: python scrapy scrapy-request

我正在尝试使用自定义中间件记录每个请求使用的带宽。使用以下代码

class CustomDownloaderMiddleware(CustomMiddleware):
    def process_response(self, request, response, spider):
        if response.url.startswith("http"):
            logging.info("{}: {}".format(response.url,len(response.body)))
            
        return response

我正在寻找的不是身体尺寸,而是带宽。但是我在response.headers中找不到Content-Length。有什么办法吗?

响应头

{b'Date': [b'Sat, 08 Aug 2020 17:26:36 GMT'], b'Expires': [b'-1'], b'Cache-Control': [b'private, max-age=0'], b'Content-Type': [b'text/html; charset=ISO-8859-1'], b'P3P': [b'CP="This is not a P3P policy! See g.co/p3phelp for more info."'], b'Server': [b'gws'], b'X-Xss-Protection': [b'0'], b'X-Frame-Options': [b'SAMEORIGIN'], b'Set-Cookie': [b'1P_JAR=2020-08-08-17; expires=Mon, 07-Sep-2020 17:26:36 GMT; path=/; domain=.google.com; Secure', b'NID=204=ht_pjEdFKBPiysMsQU8szq9znBhhZKMmgm20Pzdoi23gok-Zqb9qS91cmmyuN-Ba19DL9DV1L2iDLS2q9FJTsK7j83e7Bovd78HPstAUkZyJ7hci0VGyUzaU9T0IEjvqXu4KxG-Os034z7ytUf7wzFaVJzrrFyuA34MJ1H1dTGo; expires=Sun, 07-Feb-2021 17:26:36 GMT; path=/; domain=.google.com; HttpOnly'], b'Alt-Svc': [b'h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"']}

谢谢

0 个答案:

没有答案