我是新来的,如果这个问题无关紧要,我很抱歉。我已经从官方网页上看到了这个文件。当我浏览文档时,我遇到了这个例子:
import scrapy
from myproject.items import MyItem
class MySpider(scrapy.Spider):
name = ’example.com’
allowed_domains = [’example.com’]
start_urls = [
’http://www.example.com/1.html’,
’http://www.example.com/2.html’,
’http://www.example.com/3.html’,
]
def parse(self, response):
for h3 in response.xpath(’//h3’).extract():
yield MyItem(title=h3)
for url in response.xpath(’//a/@href’).extract():
yield scrapy.Request(url, callback=self.parse)
我知道,parse方法必须返回一个项或/和请求,但是这些返回值返回到哪里?
一个是一个项,另一个是请求,我认为这两种类型的处理方式不同,在CrawlSpider
的情况下,它有回调规则。这个回调的返回值呢?去哪里?与parse()
相同?
我很困惑的程序,即使我读了文件。。。。
根据documentation:
换言之,返回/产生的项和请求的处理方式不同,项被传递给项管道和项导出器,但请求被放入
Scheduler
中,该Downloader
通过管道将请求传递给Downloader
以发出请求并返回响应。然后,引擎接收响应并将其交给spider处理(给callback
方法)。整个数据流过程以非常详细的方式在Architecture Overview页中描述。
希望能有所帮助。
相关问题 更多 >
编程相关推荐