Home > Backend Development > Python Tutorial > Using MongoDB to store crawler data in Python

Using MongoDB to store crawler data in Python

大家讲道理
Release: 2016-11-09 11:20:36
Original
1266 people have browsed it

Now I am building a simple search engine, using the news data of Toutiao as the data source. These data are unstructured and are more suitable for storage in MongoDB.

The following is a simple example of use.

#!/usr/bin/python
# -*- coding:utf-8 -*-
 
import pymongo
 
class documentManager(object):
    def __init__(self):
        pass
 
    def connect_mongo(self):
        client = pymongo.Connection("127.0.0.1",27017)
        db = client.data_db
        collection = db.data_collection
        mydict = {"name":"Lucy", "sex":"female","job":"nurse"}
        collection.insert(mydict)
 
        for i in collection.find({"name":"Lucy"}):
            print i
 
if __name__ == '__main__':
    manager = documentManager()
    manager.connect_mongo()
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template