代码如下:
yield scrapy.Request(site, callback = self.parse_other_web, dont_filter=True)
pthon版本为:* Python3.7.4和python3.8.3
scrapy版本为: Scrapy 2.2.1
import ast
import inspect
from textwrap import dedent
class Bob:
def doit(self):
"""
this line is flush left
"""
if True:
yield 1234
if __name__ == '__main__':
b = Bob()
c = b.doit
if inspect.isgeneratorfunction(c):
tree = ast.parse(dedent(inspect.getsource(c)))
其实出现这个问题和yield是否在循环中并没有关系,而是因为yield为文件中的缩进要求较高,因此只需将文件中所有单独成行的注释全部去除即可。
https://github.com/scrapy/scrapy/issues/4477
https://github.com/rugantio/fbcrawl/issues/62
https://www.reddit.com/r/scrapy/comments/gt0cn0/setting_start_urls_to_a_set_list/?sort=top