parent
ef4d4170dc
commit
5dd1363076
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue