def process_item(self, item, spider):
# ?spider.name?????spider
# https://segmentfault.com/q/1010000004863755
con = pymysql.connect(**DB_CONFIG)
cur = con.cursor()
sql = 'insert into section(section_url,section_name,section_article_total,top_section_num,top_section_name,updatetime) ' \
'values(%s,%s,%s,%s,%s,%s)'
values = (item['section_url'], item['section_name'], item['section_article_total'],
item['top_section_num'], item['top_section_name'], item['updatetime'])
cur.execute(sql, values) # second parameter must be iterabale
con.commit()
cur.close()
con.close()
return item
评论列表
文章目录