Advertisement
Guest User

item pipeline

a guest
May 13th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. class Newpass(object):
  2. def __init__(self):
  3. self.connection = pymysql.connect(host='localhost',
  4. user='root',
  5. password='',
  6. db='newdb',
  7. charset='utf8mb4',
  8. cursorclass=pymysql.cursors.DictCursor
  9. )
  10. self.cursor = self.connection.cursor()
  11.  
  12.  
  13. def process_item(self,item,spider):
  14. try:
  15. sql = "INSERT INTO prothomalodata (serial,papername, newstitle, releasedate, collectionDate, url, newscontent, imagelink, vidlink) VALUES ( %s,%s,%s,%s,%s,%s,%s)"
  16. self.cursor.execute(sql,(item['papername'].encode('utf8'),
  17. item['title'].encode('utf8'),
  18. item['released'].encode('utf8'),
  19. item['url'].encode('utf8'),
  20. item['content'].encode('utf8'),
  21. '0'.encode('utf8'),
  22. '0'.encode('utf8'),)
  23. )
  24. self.connection.commit()
  25. self.connection.close()
  26. except pymysql.Error as e:
  27. print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement