piplines.py
再到settings.py中添加使用sql
piplines.py
再到settings.py中添加使用json
設計表結構
異步
注意:日期是str類型,要轉化成date類型
scrapy
piplines.py
ide
settings.pyurl
MYSQL_HOST = '127.0.0.1' MYSQL_DBNAME = 'spider' MYSQL_USER = 'root' MYSQL_PASSWORD = '123456'
piplines.pyspa
去重寫法設計
def do_insert(self, cursor, item): my_sql = """ insert into youwu(url, url_object_id, title, big_image_url) VALUES (%s, %s, %s, %s) on duplicate key update title=values(title), big_image_url=value(big_image_url) """ cursor.execute(my_sql, (item['url'], item['url_object_id'], item['title'], item['big_image_url']))