python爬蟲 - mongodb 存入了pymongo傳入的多個數據之後怎麼提取有用的數據
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:17:52
0
1
515

有多條這樣類似的數據

{ "_id" : ObjectId("56d06f01c3666e08d0f0c844"),
 "http://tieba.baidu.com/p/4345287300" : "【关于更新】作者原话", 
 "http://tieba.baidu.com/p/4328978430" : "服务。", 
 "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" : "来吧,你我君臣一场", 
 "http://tieba.baidu.com/p/4315565196" : "『诛魂记』第305章:临危受命", 
 "http://tieba.baidu.com/p/4340906961" : "『诛魂记』第320章:擒贼擒王", 
 "http://tieba.baidu.com/p/4337476352" : "新年到了,是不是发红包了"
 }

我想在上面的數據當中獲得能夠匹配:『誅魂記』 的連結以及後面的文字數據,例如

"http://tieba.baidu.com/p/4329505585" : "『诛魂记』第313章:泣血跪求"

這樣,
同時把得查詢的結構存到另外一個表中,並且得到

"http://tieba.baidu.com/p/4329505585" : "『诛魂记』第313章:泣血跪求"

中的連接 http://tieba.baidu.com/p/4329505585

最近開始在接觸一些爬蟲相關的東西,想自己做個東西出來,實在是捉急了。

下面是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)
过去多啦不再A梦
过去多啦不再A梦

全部回覆(1)
某草草

为什么不在抓取的时候直接根据data里面的内容是否包含“『诛魂记』”来过滤一下呢?

>>> s = "『诛魂记』第331章:圣东王府"
>>> "『诛魂记』" in s
True
>>> s = "新年快乐啦啦啦"
>>> "『诛魂记』" in s
False
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!