Arguments to Spider Constructor

344 views
Skip to first unread message

abisson

unread,
Jun 3, 2011, 6:34:04 PM6/3/11
to scrapy-users
Hey everyone,

So here is the thing. Presently I want to do the command:

scrapy crawl name_spider -a site=lol

so I did this in spider class:

class name_spider (BaseSpider):
name = name_spider
start_urls = ["https://lol.com/oas/login.do"]
site = ""

def __init__(self, name=None, **kwargs):
if name is not None:
self.name = name
elif not getattr(self, 'name', None):
raise ValueError("%s must have a name" %
type(self).__name__)
self.__dict__.update(kwargs)
if not hasattr(self, 'start_urls'):
self.start_urls = []
self.site = kwargs['site']

but I get from the command line: ERROR: Unable to find spider:
name_spider.


If I delete the __init__ function, it works, but I NEED that argument
"site"

Pablo Hoffman

unread,
Jun 4, 2011, 11:36:36 AM6/4/11
to scrapy...@googlegroups.com
You have missing quotes around "name_spider" here:

name = name_spider

Also, you don't need to implement the constructor. The BaseSpider constructor
will alredy set spider.site to the value you passed in -a site=lol

> --
> You received this message because you are subscribed to the Google Groups "scrapy-users" group.
> To post to this group, send email to scrapy...@googlegroups.com.
> To unsubscribe from this group, send email to scrapy-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/scrapy-users?hl=en.

Reply all
Reply to author
Forward
0 new messages