看板 Python 關於我們 聯絡資訊
大家好,在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呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.224.169.123 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1516365361.A.C17.html