Passing arguments to scrapy crawler as optional and not obrigatory

69 views
Skip to first unread message

dnl 31337

unread,
May 5, 2016, 1:39:19 PM5/5/16
to scrapy-users
Hi all..

there is any way to pass arguments on command line (-a) but as optional?? Exemple:

If i run:
$ scrapy crawl myspider

will work as the same way if I run:
$ scrapy crawl myspider -a test=123 -a secondtest=123



Thanks..



Travis

unread,
May 5, 2016, 2:29:38 PM5/5/16
to scrapy...@googlegroups.com
Can't you set defaults for the arguments in your spider initialization code?
--
You received this message because you are subscribed to the Google Groups "scrapy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scrapy-users...@googlegroups.com.
To post to this group, send email to scrapy...@googlegroups.com.
Visit this group at https://groups.google.com/group/scrapy-users.
For more options, visit https://groups.google.com/d/optout.

Valdir Stumm Junior

unread,
May 5, 2016, 2:55:28 PM5/5/16
to scrapy...@googlegroups.com
Hey, the arguments that you pass to a spider are turned into attributes in your Spider object. In your case, test and secondtest become attributes of your spider.

Check the example below. If you don't pass the msg parameter to this spider, it's going to print "hello!" in the output. Otherwise, it prints the value you've passed.


import scrapy



class MySpider(scrapy.Spider):

   name = 'myspider'

   msg = 'hello!'

   start_urls = ['http://scrapy.org']


   def parse(self, response):

       print self.msg


rajnish.l...@gmail.com

unread,
Dec 13, 2016, 4:30:21 AM12/13/16
to scrapy-users

Hi all

how i can call a function in scrapy and how to pass response to it ??????

Paul Tremberth

unread,
Dec 13, 2016, 4:34:39 AM12/13/16
to scrapy-users
Hi Rajnish,

Can you share some code with what you tried and explain what you expect to get as output?
(as it is, I do not understand your question, it's too generic)
 
/Paul.
Reply all
Reply to author
Forward
0 new messages