[问题] 关于scrapy中,程式码运作的问题

楼主: jamesxxx1997 (黄~)   2018-01-19 20:35:58
大家好,在scrapy中,我对于spider folder中的project(自订名字).py的运作不了解
以下是project.py中的代码
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = [
'http://quotes.toscrape.com/page/1/',
]
def parse(self, response):
for quote in response.css('div.quote'):
yield {
'text': quote.css('span.text::text').extract_first(),
'author': quote.css('span small::text').extract_first(),
'tags': quote.css('div.tags a.tag::text').extract(),
}
next_page = response.css('li.next a::attr(href)').extract_first()
if next_page is not None:
yield response.follow(next_page, callback=self.parse)
想请问一下,当我执行此段代码时,程式码的执行流程是?
个人疑惑点 :
1. 官方网站上是说,scrapy 会把response物件丢回给parse,再执行parse
,但是parse是一个generator,scrapy是如何执行此generator呢?

Links booklink

Contact Us: admin [ a t ] ucptt.com