Advertisement
Guest User

Untitled

a guest
Sep 10th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class MysqlPipeline(object):
  2.  
  3. def open_spider(self, spider):
  4. self.con = pymysql.connect(host="localhost", user="root", password="password", db="articals", port=3306)
  5. self.cur = self.con.cursor()
  6.  
  7. def process_item(self, item, spider):
  8.  
  9. str = "insert into one(title, content) values({}, {})".format(item['title'], item['content'])
  10. self.cur.execute(str)
  11. self.con.commit()
  12.  
  13. def close_spider(self, spider):
  14. self.con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement