python爬虫 - mongodb 存入了pymongo传入的多个数据之后怎么提取有用的数据
问题描述
有多条这样类似的数据
{ '_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)
问题解答
回答1:为什么不在抓取的时候直接根据data里面的内容是否包含“『诛魂记』”来过滤一下呢?
>>> s = '『诛魂记』第331章:圣东王府'>>> '『诛魂记』' in sTrue>>> s = '新年快乐啦啦啦'>>> '『诛魂记』' in sFalse
相关文章:
1. mysql - 一个表和多个表是多对多的关系,该怎么设计2. python 如何实现PHP替换图片 链接3. 一个mysql联表查询的问题4. html5 - iOS的webview加载出来的H5网页,怎么修改html标签select的样式字体?5. javascript - git clone 下来的项目 想在本地运行 npm run install 报错6. mysql优化 - mysql count(id)查询速度如何优化?7. 主从备份 - 跪求mysql 高可用主从方案8. angular.js - 三大框架react、vue、angular的分析9. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?10. python如何不改动文件的情况下修改文件的 修改日期
