Untitled
unknown
plain_text
a year ago
1.3 kB
14
Indexable
import sqlite3
class SQLitePipeline(object):
def open_spider(self, spider):
self.connection = sqlite3.connect('proxies.db')
self.cursor = self.connection.cursor()
# Criar a tabel
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS proxies(
ip_address TEXT NOT NULL PRIMARY KEY,
port NUMBER,
code TEXT,
country TEXT,
anonimity TEXT,
google TEXT,
https TEXT,
last_checked TEXT
)
''')
self.connection.commit()
def close_spider(self, spider):
self.connection.close()
def process_item(self, item, spider):
self.cursor.execute('''
INSERT OR IGNORE INTO proxies(ip_address,port,code,country,anonimity,google,https,last_checked) VALUES(?,?,?,?,?,?,?,?)
''', (
item.get('ip_address'),
item.get('port'),
item.get('code'),
item.get('country'),
item.get('anonimity'),
item.get('google'),
item.get('https'),
item.get('last_checked'),
))
self.connection.commit()
return itemEditor is loading...
Leave a Comment