-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpipelines.py
More file actions
46 lines (36 loc) · 1.41 KB
/
pipelines.py
File metadata and controls
46 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import sqlite3
class MonsterPipeline(object):
def __init__(self):
self.create_connection() #whenevr the class is initialized the two methods are automatically called
self.create_table()
def create_connection(self):
self.conn = sqlite3.connect("jobinformation.db") #exits connect not exits create
self.curr = self.conn.cursor()
def create_table(self):
self.curr.execute("""DROP TABLE IF EXISTS jobtable_tb""")
self.curr.execute("""create table jobtable_tb(
title text,
companyname text,
companyurl text,
jobLocationRegion text,
jobLocationCity text,
jobdescription text
)""")
def process_item(self, item, spider):
self.store_db(item)
return item
def store_db(self,item):
self.curr.execute("""insert into jobtable_tb values(?,?,?,?,?,?)""",(
item['title'],
item['companyname'],
item["companyurl"],
item['jobLocationRegion'],
item['jobLocationCity'],
item['jobdescription']
))
self.conn.commit()