|
|
|
@ -32,8 +32,8 @@ class MysqlPipeline(object):
|
|
|
|
|
|
|
|
|
|
def process_item(self, item, spider):
|
|
|
|
|
insert_sql = """
|
|
|
|
|
insert into jobbole_article(title, url ,url_object_id, front_image_url, front_image_path, parise_nums, comment_nums, fav_nums, tags, content, create_date)
|
|
|
|
|
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE parise_nums=VALUES(parise_nums)
|
|
|
|
|
insert into jobbole_article(title, url ,url_object_id, front_image_url, front_image_path, parise_nums, comment_nums, fav_nums, tags, content, create_date, where_from)
|
|
|
|
|
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE parise_nums=VALUES(parise_nums)
|
|
|
|
|
"""
|
|
|
|
|
params = list()
|
|
|
|
|
params.append(item.get("title", ""))
|
|
|
|
@ -48,6 +48,7 @@ class MysqlPipeline(object):
|
|
|
|
|
params.append(item.get("tags", ""))
|
|
|
|
|
params.append(item.get("content", ""))
|
|
|
|
|
params.append(item.get("create_date", "1970-07-01"))
|
|
|
|
|
params.append(item.get("where_from", ""))
|
|
|
|
|
self.cursor.execute(insert_sql, tuple(params))
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return item
|
|
|
|
@ -83,8 +84,8 @@ class MysqlTwistedPipline(object):
|
|
|
|
|
def do_insert(self, cursor, item):
|
|
|
|
|
# 执行具体的插入
|
|
|
|
|
insert_sql = """
|
|
|
|
|
insert into jobbole_article(title, url ,url_object_id, front_image_url, front_image_path, parise_nums, comment_nums, fav_nums, tags, content, create_date)
|
|
|
|
|
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE parise_nums=VALUES(parise_nums)
|
|
|
|
|
insert into jobbole_article(title, url ,url_object_id, front_image_url, front_image_path, parise_nums, comment_nums, fav_nums, tags, content, create_date, where_from)
|
|
|
|
|
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE parise_nums=VALUES(parise_nums)
|
|
|
|
|
"""
|
|
|
|
|
params = list()
|
|
|
|
|
params.append(item.get("title", ""))
|
|
|
|
@ -99,6 +100,7 @@ class MysqlTwistedPipline(object):
|
|
|
|
|
params.append(item.get("tags", ""))
|
|
|
|
|
params.append(item.get("content", ""))
|
|
|
|
|
params.append(item.get("create_date", "1970-07-01"))
|
|
|
|
|
params.append(item.get("where_from", ""))
|
|
|
|
|
# 根据不同的item 构建不同的sql语句并插入到mysql中
|
|
|
|
|
cursor.execute(insert_sql, tuple(params))
|
|
|
|
|
|
|
|
|
|