上传文件至 'dagongPro'

新增:将图片url保存到mysql数据库
This commit is contained in:
link_1999 2022-04-06 21:45:02 +08:00
parent ef4d4170dc
commit 5dd1363076
1 changed files with 5 additions and 3 deletions

View File

@ -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()
self.conn.close()