为列表中的每个 url 重新启动scrapy

问题描述

我正在尝试运行一个scrapy bot,它将为列表中给定的每个url重复运行蜘蛛。我写到现在的代码如下

var pfa = doc.Element("PFA");
IList<XElement> entities = pfa.Elements("Entity").ToList();
foreach (var entity in entities)
{
    entity.Remove(); // Remove all the <Entity> tags from <PFA>
}
var record = new XElement("Record");
pfa.Add(record); // Add the new <Record>
foreach (var entity in entities) 
{
    record.Add(entity); // Add the <Entity> tags back to <Record>
}

蜘蛛本身在第一个 url 上运行良好,但是一旦循环命中它就会给出错误 def run_spider(url_list,allowed_list): runner = CrawlerRunner(get_project_settings()) d = runner.crawl('scraper',start_urls=url_list,allowed_domains=allowed_list) d.addBoth(lambda _: reactor.stop()) reactor.run() for start,allowed in zip(start_url,allowedUrl): url_list = [] allowed_list = [] url_list.append(start) allowed_list.append(allowed) print(type(url_list),type(allowed_list)) run_spider(url_list,allowed_list) ,完整的回溯在这里:

twisted.internet.error.ReactorNotRestartable

我正在遵循文档中描述的方法,但如何为循环中的每个项目重新启动蜘蛛。任何建议都会非常有帮助。

P:S:: 当简单地传递允许的域和起始 url 时,蜘蛛机器人本身就可以正常工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)