python爬蟲 - mongodb 存入了pymongo傳入的多個(gè)數(shù)據(jù)之后怎么提取有用的數(shù)據(jù)
問題描述
有多條這樣類似的數(shù)據(jù)
{ '_id' : ObjectId('56d06f01c3666e08d0f0c844'), 'http://tieba.baidu.com/p/4345287300' : '【關(guān)于更新】作者原話', 'http://tieba.baidu.com/p/4328978430' : '服務(wù)。', 'http://tieba.baidu.com/p/4372502982' : '『誅魂記』第331章:圣東王府', 'http://tieba.baidu.com/p/4355241530' : '『誅魂記』第322章:麒麟之威', 'http://tieba.baidu.com/p/4329505585' : '『誅魂記』第313章:泣血跪求', 'http://tieba.baidu.com/p/4343824178' : '新年快樂啦啦啦', 'http://tieba.baidu.com/p/4328603018' : '寫小說好看嗎', 'http://tieba.baidu.com/p/4333008061' : '來吧,你我君臣一場(chǎng)', 'http://tieba.baidu.com/p/4315565196' : '『誅魂記』第305章:臨危受命', 'http://tieba.baidu.com/p/4340906961' : '『誅魂記』第320章:擒賊擒王', 'http://tieba.baidu.com/p/4337476352' : '新年到了,是不是發(fā)紅包了' }
我想在上面的數(shù)據(jù)當(dāng)中獲得能夠匹配:『誅魂記』 的連接以及后面的文本數(shù)據(jù),例如
'http://tieba.baidu.com/p/4329505585' : '『誅魂記』第313章:泣血跪求'
這樣,同時(shí)把得查詢到的結(jié)構(gòu)存到另外一個(gè)表中,以及得到
'http://tieba.baidu.com/p/4329505585' : '『誅魂記』第313章:泣血跪求'
中的連接 http://tieba.baidu.com/p/4329505585
最近開始在接觸一些爬蟲相關(guān)的東西,想自己做個(gè)東西出來,實(shí)在是捉急了。
下面是python里面的代碼
def craw(self, root_urls):for new_url in root_urls: html_cont = self.downloader.download(new_url) new_chapter_urls, new_linkdatas = self.parser.parselink(root_chapter_url, html_cont) mid_data = zip(new_chapter_urls,new_linkdatas) mid_mid_datas = dict((new_chapter_urls,new_linkdatas) for new_chapter_urls,new_linkdatas in mid_data) c = pymongo.MongoClient(host=’127.0.0.1’, port=27017) db = c.spider db.chapter_datas.insert(mid_mid_datas, check_keys=False)
問題解答
回答1:為什么不在抓取的時(shí)候直接根據(jù)data里面的內(nèi)容是否包含“『誅魂記』”來過濾一下呢?
>>> s = '『誅魂記』第331章:圣東王府'>>> '『誅魂記』' in sTrue>>> s = '新年快樂啦啦啦'>>> '『誅魂記』' in sFalse
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個(gè)布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語法錯(cuò)誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?

網(wǎng)公網(wǎng)安備