課程
/后端開發(fā)
/Python
/Python最火爬蟲框架Scrapy入門與實(shí)踐
?怎么插入到sql server數(shù)據(jù)庫(kù)中,mssql?
2019-09-11
源自:Python最火爬蟲框架Scrapy入門與實(shí)踐 2-8
正在回答
這是我的代碼??插入到mysql中 #?-*-?coding:?utf-8?-*- import?pymysql #?Define?your?item?pipelines?here # #?Don't?forget?to?add?your?pipeline?to?the?ITEM_PIPELINES?setting #?See:?https://docs.scrapy.org/en/latest/topics/item-pipeline.html class?DoubanPipeline(object): ????def?__init__(self): ????????self.mydb?=?pymysql.connect(host="127.0.0.1",user="root",password="020202",db="douban",charset="utf8",use_unicode=True) ????????self.cursor?=?self.mydb.cursor() ????def?process_item(self,?item,?spider): ????????insert_sql?=?"""insert?into?movie(serial_number,?movie_name,?introduce,?star,?evaluate,?describetion) ????????????????????????????????values?(%s,?%s,?%s,?%s,%s,%s)""" ????????#?使用`占位符 ????????self.cursor.execute(insert_sql,(item['serial_number'],item['movie_name'],item['introduce'],item['star'],item['evaluate'],item['describetion'])) ????????#用commit()才會(huì)提交到數(shù)據(jù)庫(kù) ????????self.mydb.commit() ????def?close_spider(self,spider): ????????self.cursor.close() ????????self.mydb.close()
舉報(bào)
做為爬蟲工程師Python Scrapy主流爬蟲框架你必須要會(huì)!
1 回答向mongodb插入數(shù)據(jù)時(shí)報(bào)錯(cuò)
1 回答插入數(shù)據(jù)self.post.insert(data)時(shí)報(bào)錯(cuò)pymongo.errors.ServerSelectionTimeoutError
2 回答使用MySql如何插入數(shù)據(jù)呢
2 回答數(shù)據(jù)庫(kù)中文亂碼問題
2 回答請(qǐng)問我這個(gè)是什么問題呀,mongoDB數(shù)據(jù)庫(kù)也有數(shù)據(jù)。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-12-23