我试图请求参数site_search_url
,但是当我运行时出现以下错误:``:
start_requests = iter(self.spider.start_requests())
TypeError: 'NoneType' object is not iterable
代码:
class BrickSetSpider(scrapy.Spider):
def __init__(self, site_search_url):
self.site_search_url = site_search_url
def start_requests(self):
se_base = 'http://www.se.com/search?q=site:'
start_urls = [ se_base + self.site_search_url, ]
def parse(self, response):
yield scrapy.Request(
response.urljoin(next_page),
callback=self.parse
)
我在这里做错了什么?
谢谢
答案 0 :(得分:9)
你的start_requests
什么都不返回,这意味着在Python中返回None
,而它应该返回一个Request
个可迭代的对象。在您的情况下,最简单的方法是在start_urls
中填充__init__
并且不要覆盖start_requests
:
class BrickSetSpider(scrapy.Spider):
se_base = 'http://www.se.com/search?q=site:'
def __init__(self, site_search_url):
self.start_urls = [self.se_base + site_search_url]
def parse(self, response):
yield scrapy.Request(
response.urljoin(next_page),
callback=self.parse
)