From 5dd136307647d6bd3398334b42de3510dc5ab86e Mon Sep 17 00:00:00 2001 From: link_1999 <1402246900@qq.com> Date: Wed, 6 Apr 2022 21:45:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'dagongPro'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增:将图片url保存到mysql数据库 --- dagongPro/pipelines.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dagongPro/pipelines.py b/dagongPro/pipelines.py index ef28503..d4baf33 100644 --- a/dagongPro/pipelines.py +++ b/dagongPro/pipelines.py @@ -8,6 +8,7 @@ from itemadapter import ItemAdapter import pymysql + class DagongwangproPipeline: def process_item(self, item, spider): @@ -17,7 +18,7 @@ class DagongwangproPipeline: content = item['content'] date = item['date'] - news_path = './新闻/军事新闻/' + title + '.txt' + news_path = './新闻/内地新闻/' + title + '.txt' with open(news_path, 'w', encoding='utf-8') as fp: fp.write(date+'\n'+content) @@ -33,7 +34,7 @@ class mysqlPileLine(object): self.cursor = self.conn.cursor() try: - self.cursor.execute('insert into junshi_news values("%s", "%s", "%s")'%(item['title'], item['date'], item['content'])) + self.cursor.execute('insert into junshi_news values("%s", "%s", "%s", "%s")'%(item['title'], item['date'], item['content'], item['src'])) self.conn.commit() except Exception as e: print(e) @@ -43,4 +44,5 @@ class mysqlPileLine(object): def close_spider(self, spider): self.cursor.close() - self.conn.close() \ No newline at end of file + self.conn.close() +