Note that there are some explanatory texts on larger screens.

plurals
  1. POScrapy request+response+download time
    primarykey
    data
    text
    <p><strong>UPD</strong>: Not close question because I think my way is not so clear as should be</p> <p>Is it possible to get current request + response + download time for saving it to Item?</p> <p>In "plain" python I do</p> <pre><code>start_time = time() urllib2.urlopen('http://example.com').read() time() - start_time </code></pre> <p>But how i can do this with Scrapy?</p> <p><strong>UPD</strong>:</p> <p>Solution enought for me but I'm not sure of quality of results. If you have many connections with timeout errors <code>Download time</code> may be wrong (even DOWNLOAD_TIMEOUT * 3)</p> <p>For </p> <p>settings.py</p> <pre><code>DOWNLOADER_MIDDLEWARES = { 'myscraper.middlewares.DownloadTimer': 0, } </code></pre> <p>middlewares.py</p> <pre><code>from time import time from scrapy.http import Response class DownloadTimer(object): def process_request(self, request, spider): request.meta['__start_time'] = time() # this not block middlewares which are has greater number then this return None def process_response(self, request, response, spider): request.meta['__end_time'] = time() return response # return response coz we should def process_exception(self, request, exception, spider): request.meta['__end_time'] = time() return Response( url=request.url, status=110, request=request) </code></pre> <p>inside spider.py in <code>def parse(...</code></p> <pre><code>log.msg('Download time: %.2f - %.2f = %.2f' % ( response.meta['__end_time'], response.meta['__start_time'], response.meta['__end_time'] - response.meta['__start_time'] ), level=log.DEBUG) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload