我有一个 scrapy pipelines.py 我想获得给定的参数。在我的 Spider.py 中,它工作得非常完美:
class MySpider( CrawlSpider ):
def __init__(self, host='', domain_id='', *args, **kwargs):
super(MySpider, self).__init__(*args, **kwargs)
print user_id
...
现在,我需要 pipelines.py 中的“user_id”来创建像“domain-123.db”这样的 sqlite 数据库。我在整个网络上搜索我的问题,但找不到任何解决方案。
有人能帮我吗?
PS:是的,我尝试了管道类中的 super() 函数,例如间谍.py,但它不起作用。
设置里面的参数spider
的构造函数:
class MySpider(CrawlSpider):
def __init__(self, user_id='', *args, **kwargs):
self.user_id = user_id
super(MySpider, self).__init__(*args, **kwargs)
并在中阅读它们open_spider()你的管道的方法:
def open_spider(self, spider):
print spider.user_id
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)