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

adding spider args as attrs to docs #1719

Closed
wants to merge 1 commit into from

Conversation

demelziraptor
Copy link

No description provided.

@codecov-io
Copy link

Current coverage is 82.99%

Merging #1719 into master will not affect coverage as of f72017a

Powered by Codecov. Updated on successful CI builds.

@@ -283,7 +283,19 @@ Spider arguments are passed through the :command:`crawl` command using the

scrapy crawl myspider -a category=electronics

Spiders receive arguments in their constructors::
Spider arguments are exposed as attributes::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @demelziraptor !
This is about documenting the feature of spider arguments being exposed as attributes, right? (this line: https://github.com/scrapy/scrapy/blob/master/scrapy/spiders/__init__.py#L30)

From the example it isn't clear what this is trying to show.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly @eliasdorneles, from the current docs it seems like the only way to access spider input arguments is from the constructor arguments.

Maybe this example is better?

    import scrapy

    class MySpider(scrapy.Spider):
        name = 'myspider'

        def parse(self, response):
            products = response.css('.%s' % self.category)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think it'll need more than an example.
Looking at the example alone it looks like broken code. :)

Perhaps adding a default as a class attribute, like:

import scrapy

class MySpider(scrapy.Spider):
    name = 'myspider'
    category = 'default-category'  # use -a category=another from the cmdline to override this

    def parse(self, response):
        products = response.css('.%s' % self.category)

This may deserve its own section in the docs really. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add a spider that can be copied, ran with runspider and get a result; something somehow interactive. Doesn't need to browse, it can do some comparison and close, maybe using start_requests or adding a signal.

@redapple redapple added the docs label Jan 26, 2016
@kmike
Copy link
Member

kmike commented May 18, 2017

Closing it in favor of #2483. Thanks @demelziraptor!

@kmike kmike closed this May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants