1

I have created the following python file named test.py:

import scrapy


class EventsSpider(scrapy.Spider):
name = "test"
start_urls = [
    'https://www.granteatrocc.com/programacion.php',
]

    def parse(self, response):
        print "\nBEFORE-------------------------------------------------\n"
        scrapy.Request("https://stackoverflow.com/questions/6453269/jquery-select-element-by-xpath", callback=self.parse_two)
        print "\nAFTER-------------------------------------------------\n"

    def parse_two(self, response):
        print "THIS IS WORKING"

And I Execute it using the following command:

scrapy runspider test.py

Obviously this example is a simplified version of a Crawler that must follow links to get extra fields. The output I get is the following. As you can see, the string "THIS IS WORKING" is never printed, so I understand that ````parse_two function is never called:

Jesuss-MacBook-Pro:tutorial jesusredondogarcia$ scrapy runspider test.py
2017-10-24 10:19:09 [scrapy.utils.log] INFO: Scrapy 1.4.0 started (bot: scrapybot)
2017-10-24 10:19:09 [scrapy.utils.log] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}
2017-10-24 10:19:09 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.logstats.LogStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.corestats.CoreStats']
2017-10-24 10:19:09 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
 'scrapy.downloadermiddlewares.retry.RetryMiddleware',
 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
 'scrapy.downloadermiddlewares.stats.DownloaderStats']
2017-10-24 10:19:09 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
 'scrapy.spidermiddlewares.referer.RefererMiddleware',
 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
 'scrapy.spidermiddlewares.depth.DepthMiddleware']
2017-10-24 10:19:09 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2017-10-24 10:19:09 [scrapy.core.engine] INFO: Spider opened
2017-10-24 10:19:09 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2017-10-24 10:19:09 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2017-10-24 10:19:10 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.granteatrocc.com/programacion.php> (referer: None)
BEFORE-------------------------------------------------
AFTER-------------------------------------------------
2017-10-24 10:19:10 [scrapy.core.engine] INFO: Closing spider (finished)
2017-10-24 10:19:10 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 234,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 9029,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2017, 10, 24, 8, 19, 10, 542732),
 'log_count/DEBUG': 2,
 'log_count/INFO': 7,
 'memusage/max': 46268416,
 'memusage/startup': 46268416,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2017, 10, 24, 8, 19, 9, 237051)}
2017-10-24 10:19:10 [scrapy.core.engine] INFO: Spider closed (finished)
Jesus
  • 655
  • 1
  • 7
  • 21

1 Answers1

2

IIRC, the parse method should use the yield keyword, while you're evaluating the Request inplace

omu_negru
  • 4,642
  • 4
  • 27
  • 38
  • You are right, after much testing I was able solve this as soon as I realised I had to yield the request I defined! Thanks a lot – Jesus Oct 24 '17 at 10:41