Я хочу использовать подкласс для запуска моего паука с другим URL и сохранения информации через цикл.Вот мой подход:
class Run_Spider_From_SubClass:
def __init__(self, url_list, *args, **kwargs):
super().__init__(*args, **kwargs)
self.url_list = url_list
def run_spider_in_loop(self):
#here I start feeding urls, but more important I can save info for each
#crawling process, and then restart the process with another url along
#loop.
for url in self.url_list:
process = CrawlerProcess(get_project_settings()) # this drive the scrapy to use configuration in 'settings.py', all class must start from this
process.crawl('MySpider', url)
process.start()
save_info # any codes that save info from spider into target file
после этого я сталкиваюсь с проблемой реактора:
Traceback (most recent call last):
File "G:/python/test/scrapy_test/test4.py", line 45, in <module>
Run_Spider_From_SubClass(url_list).run_spider_in_loop()
File "G:/python/test/scrapy_test/test4.py", line 34, in run_spider_in_loop
process.start()
File "C:\Users\super\AppData\Roaming\Python\Python36\site-
packages\scrapy\crawler.py", line 291, in start
reactor.run(installSignalHandlers=False) # blocking call
File "C:\Users\super\AppData\Roaming\Python\Python36\site-
packages\twisted\internet\base.py", line 1266, in run
self.startRunning(installSignalHandlers=installSignalHandlers)
File "C:\Users\super\AppData\Roaming\Python\Python36\site-
packages\twisted\internet\base.py", line 1246, in startRunning
ReactorBase.startRunning(self)
File "C:\Users\super\AppData\Roaming\Python\Python36\site-
packages\twisted\internet\base.py", line 754, in startRunning
raise error.ReactorNotRestartable()
twisted.internet.error.ReactorNotRestartable
как преодолеть эту ошибку реактора, спасибо.