File: fetch.py

package info (click to toggle)
python-scrapy 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,904 kB
  • ctags: 2,981
  • sloc: python: 15,349; xml: 199; makefile: 68; sql: 64; sh: 34
file content (17 lines) | stat: -rw-r--r-- 560 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from scrapy.http import Request
from scrapy.core.manager import scrapymanager

def fetch(urls):
    """Fetch a list of urls and return a list of the downloaded Scrapy
    Responses.

    This is a blocking function not suitable for calling from spiders. Instead,
    it is indended to be called from outside the framework such as Scrapy
    commands or standalone scripts.
    """
    responses = []
    requests = [Request(url, callback=responses.append, dont_filter=True) \
        for url in urls]
    scrapymanager.runonce(*requests)
    return responses