I followed the advice from these two posts as I am also trying to create a generic scrapy spider:
How to pass a user defined argument in scrapy spider
Creating a generic scrapy spider
But I'm getting an error that the variable I am supposed to be passing as an argument is not defined. Am I missing something in my init method?
Code:
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from data.items import DataItem
class companySpider(BaseSpider):
name = "woz"
def __init__(self, domains=""):
'''
domains is a string
'''
self.domains = domains
deny_domains = [""]
start_urls = [domains]
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('/html')
items = []
for site in sites:
item = DataItem()
item['text'] = site.select('text()').extract()
items.append(item)
return items
Here is my command-line:
scrapy crawl woz -a domains="http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"
And here is the error:
NameError: name 'domains' is not defined