[PYTHON] How to pass settings to Item Pipeline in Scrapy

If only from_settings is defined, it will not be valid through Item Pipeline. You need to redefine it properly with init as shown below.

class MySQLStorePipeline(object):

    @classmethod
    def from_settings(cls, settings):
        return cls(settings.get('DB_SETTING'))

    def __init__(self, db_settings):
        db.init_session(db_settings)

    def process_item(self, item, spider):
        shop = Shop(
            brand_id=1,
            name=item['name'],
            address=item['address'])
        db.db_session.add(shop)
        db.db_session.commit()
        return item

Recommended Posts

How to pass settings to Item Pipeline in Scrapy
How to pass matplotlib backend settings in environment variables
How to separate pipeline processing code into files by spider in Scrapy
How to specify a schema in Django's database settings
How to develop in Python
How to handle session in SQLAlchemy
How to use classes in Theano
How to write soberly in pandas
How to collect images in Python
How to update Spyder in Anaconda
How to use SQLite in Python
How to convert 0.5 to 1056964608 in one shot
How to get started with Scrapy
How to reflect CSS in Django
How to kill processes in bulk
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
Pass arguments to Task in discord.py
How to run TensorFlow 1.0 code in 2.0
How to handle Japanese in Python
How to log in to Docker + NGINX
How to call PyTorch in Julia
How to pass arguments to a Python script in SPSS Modeler Batch
How to configure CORS settings for Azure storage service in Python
How to use calculated columns in CASTable
[Introduction to Python] How to use class in Python?
How to suppress display error in matplotlib
How to dynamically define variables in Python
How to do R chartr () in Python
How to convert csv to tsv in CLI
How to delete expired sessions in Django
How to use Google Test in C
How to implement nested serializer in drf-flex-fields
How to work with BigQuery in Python
How to execute commands in jupyter notebook
How to do'git fetch --tags' in GitPython
How to get a stacktrace in python
How to display multiplication table in python
How to extract polygon area in Python
How to reassign index in pandas dataframe
How to check opencv version in python
How to enable SSL (TLS) in Apache
How to use Anaconda interpreter in PyCharm
How to specify non-check target in Flake8
How to handle consecutive values in MySQL
[Python / Tkinter] How to pass arguments to command
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
"How to pass PATH" to learn with homebrew
How to do Server-Sent Events in Django
How to use regular expressions in Python
How to implement Scroll View in pythonista 1
How to convert DateTimeField format in Django
How to use Map in Android ViewPager
How to display Hello world in python
How to read CSV files in Pandas
How to change editor color in PyCharm