-1

I am working on a paid proxy spider template and would like the ability to pass in a new argument on the command line for a Scrapy crawler. How can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Gregory Williams
  • 453
  • 5
  • 18

1 Answers1

2

This is achievable by using kwargs in your spider's __init__-Method:

import scrapy


class YourSpider(scrapy.Spider):
    name = your_spider

    def __init__(self, *args, **kwargs):
        super(YourSpider, self).__init__(*args, **kwargs)
        self.your_arg = kwargs.get("your_cmd_arg", 42)

Now it would be possible to call the spider as follows:
scrapy crawl your_spider -a your_cmd_arg=foo

For more information on the topic, feel free to check this page in the Scrapy documentation.

Patrick Klein
  • 1,161
  • 3
  • 10
  • 23