Using arguments in scrapy pipeline on __init__(在 __init__ 上的 scrapy 管道中使用参数)
问题描述
我有一个scrapy pipelines.py,我想得到给定的参数.在我的 spider.py 中,它运行良好:
i have a scrapy pipelines.py and i want to get the given arguments. In my spider.py it works perfect:
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 数据库.我在整个网络上搜索我的问题,但我找不到任何解决方案.
Now, i need the "user_id" in my pipelines.py to create the sqlite database like "domain-123.db". I search the whole web about my problem, but i cant find any solution.
有人可以帮我吗?
PS:是的,我在管道类中尝试了 super() 函数,例如 spyer.py,它不起作用.
PS: Yes, i try'ed the super() function within my pipelines Class like the spyer.py, it dont work.
推荐答案
在 spider
的构造函数中设置参数:
Set the arguments inside the spider
's constructor:
class MySpider(CrawlSpider):
def __init__(self, user_id='', *args, **kwargs):
self.user_id = user_id
super(MySpider, self).__init__(*args, **kwargs)
并在 open_spider()
中阅读它们a> 管道方法:
And read them in the open_spider()
method of your pipeline:
def open_spider(self, spider):
print spider.user_id
这篇关于在 __init__ 上的 scrapy 管道中使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 __init__ 上的 scrapy 管道中使用参数


- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01