Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note about using twisted.internet.defer.inlineCallbacks directly instead of inline_requests #10

Open
rmax opened this issue Oct 18, 2016 · 3 comments

Comments

@rmax
Copy link
Owner

rmax commented Oct 18, 2016

No description provided.

@poupryc
Copy link

poupryc commented Jan 1, 2020

Could you provide an example please? I try to use @inlineCallbacks without success.

@rmax
Copy link
Owner Author

rmax commented Jan 2, 2020

@HelloEdit If I remember correctly, if you use @inlineCallbacks then you have to return deferreds and to return the final item you would use defer.returnValue(item).

@poupryc
Copy link

poupryc commented Jan 2, 2020

I think I've managed otherwise, without inline_request.

# -*- coding: utf-8 -*-
import scrapy
import re
from twisted.internet.defer import inlineCallbacks

from sherlock import utils, items, regex


class PagesSpider(scrapy.spiders.SitemapSpider):
    name = 'pages'
    allowed_domains = ['thing.com']
    sitemap_follow = [r'sitemap_page']

    def __init__(self, site=None, *args, **kwargs):
        super(PagesSpider, self).__init__(*args, **kwargs)

    @inlineCallbacks
    def parse(self, response):
        # things
        request = scrapy.Request("https://google.com")
        response = yield self.crawler.engine.download(request, self) 
        # Twisted execute the request and resume the generator here with the response
        print(response.text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants