【发布时间】:2016-07-24 22:02:23
【问题描述】:
Scrapy 版本:1.0.5
我已经搜索了很长时间,但是大多数解决方法在当前的 Scrapy 版本中都不起作用。
我的spider在jingdong_spider.py中定义,运行spider的接口(通过Scrapy Documentation学习)如下:
# interface
def search(keyword):
configure_logging({'LOG_FORMAT': '%(levelname)s: %(message)s'})
runner = CrawlerRunner()
d = runner.crawl(JingdongSpider,keyword)
d.addBoth(lambda _: reactor.stop())
reactor.run() # the script will block here until the crawling is finished
然后在temp.py中调用上面的search(keyword)来运行spider。
现在的问题是:我调用了一次 search(keyword),它运行良好。但我调用了两次,例如,
在 temp.py 中
search('iphone')
search('ipad2')
它报告了:
Traceback(最近一次调用最后一次):文件 “C:/Users/jiahao/Desktop/code/bbt_climb_plus/temp.py”,第 7 行,在 search('ipad2') 文件 "C:\Users\jiahao\Desktop\code\bbt_climb_plus\bbt_climb_plus\spiders\jingdong_spider.py", 第 194 行,搜索中 reactor.run() # 脚本会在这里阻塞,直到爬取完成 File “C:\Python27\lib\site-packages\twisted\internet\base.py”,第 1193 行, 运行中 self.startRunning(installSignalHandlers=installSignalHandlers) 文件“C:\Python27\lib\site-packages\twisted\internet\base.py”,行 1173,在开始运行 ReactorBase.startRunning(self) 文件“C:\Python27\lib\site-packages\twisted\internet\base.py”,第 684 行,在 开始跑步 raise error.ReactorNotRestartable() twisted.internet.error.ReactorNotRestartable
第一次搜索(keyword)成功,后面找错了。
你能帮忙吗?
【问题讨论】:
标签: python python-2.7 scrapy twisted