I work with sqlalchemy 1.1 and scrapy. I am currently using a pipeline to store the extracted data in a sqlite table through sqlalchemy. I would like to dynamically create a table to place the item being cleared.
My static pipeline element looks like this:
class SQLlitePipeline(object): def __init__(self): db_path = "sqlite:///"+settings.SETTINGS_PATH+"\\data.db" _engine = create_engine(db_path) _connection = _engine.connect() _metadata = MetaData() _stack_items = Table(table_name, _metadata, Column("id", Integer, primary_key=True), Column("value", Text)) Column("value2", Text)) _metadata.create_all(_engine) self.connection = _connection self.stack_items = _stack_items def process_item(self, item, spider): try: ins_query = self.stack_items.insert().values( value=item['value'], value2=item['value2'],) self.connection.execute(ins_query) except IntegrityError: print('THIS IS A DUP') return item
items.py:
class Filtered_Item(scrapy.Item): value= scrapy.Field() value2= scrapy.Field()
How can I change the pipeline above to dynamically create and insert values ββof the filtered elements instead of being encoded as they are now?
source share