vscode debug python scrapy没有步入回调函数

问题描述 投票:0回答:2

测试爬虫:

class QuotesSpider(scrapy.Spider):
name = "quotes"

def start_requests(self):
    urls = [
        'http://quotes.toscrape.com/page/1/',
        'http://quotes.toscrape.com/page/2/',
    ]
    for url in urls:
        yield scrapy.Request(url=url, callback=self.parse)

def parse(self, response):
    page = response.url.split("/")[-2]
    filename = 'quotes-%s.html' % page
    with open(filename, 'wb') as f:
        f.write(response.body)
    self.log('Saved file %s' % filename)

我写了一个main.py:

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
execute(["scrapy","crawl","quotes"])

并且我添加了python scrapy调试器配置,一切都很好,直到命中yield scrapy.Request(url = url,callback = self.parse)它没有进入回调解析函数?

visual-studio-code scrapy vscode-debugger
2个回答
1
投票

好的,现在我知道为什么,因为yield请求是异步的,并且在子线程返回结果后将调用回调,所以稍等一下,它最终将调试到解析函数中


0
投票

你确定你的parse功能在课堂内吗?此代码段看起来像是有错误的缩进。

© www.soinside.com 2019 - 2024. All rights reserved.