Basic installation and operation Mongdb scrapy the link Mongodb

# Installation mongodb "lower
window" - (. 1) mounted on the URL Here Insert Picture Description
https://www.mongodb.com/download-center/community, ---- Here Insert Picture Description
(2) - Here Insert Picture Description
(3) ---- (4 ) a crucial step, careful and other flowers are gone! ! ! ! ! ! ! ! ! ! ! ! !Here Insert Picture Description

After completion of the installation operation ##
because MongoDB directory data stored in directory db. But this will not take the initiative to create the data directory, we need to create it after installation. Note that the data should be placed in the root directory ((eg: C: \ or D: \, etc.).

在本教程中,我们已经在 C 盘安装了 mongodb,现在让我们创建一个 data 的目录然后在 data 目录里创建 db 目录。
——1:(1)C: (进入c盘)(2)mkdir data (3)cd data (4)mkdir db 然后就创建 完成了
——2:(1)需要你在命令行下cd 进入mongodb 的 bin 文件下 然后执行(C:\mongodb\bin\你已经进入该bin文件的话就直接执行)mongod --dbpath c:\data\db (2)执行完第一步后,就再执行 mongo.exe
——-3:(1)以管理员的模式打开命令行。《切记前面的命令行别关闭》,输入net start MongoDB 就开启了,net stop MongoDB就关闭了。
##安装mongodb的一个可视化工具 网址如下https://robomongo.org/,安装容易下面开始使用
###mongodb工具的超级基础使用,
——(1)进入该工具后看左上方有个按钮是两个小电脑,点击他,有个弹窗,点击弹窗上面的create,又有一个小弹窗,把里面的name( 自己取也可以 )然后save (保存就可以了),最后 以刚才的的相同的方式点击两台小电脑,这时候你就可以在弹窗里面看到自己刚创建的数据库,点击connect链接起来就大功告成了。
##配置scrapy文件 ,来链接数据库。————目的是把 scrapy 爬出来的内容保存在数据库里
- In setting the Mongoip = '192.xxx.xx.xx' #mongoDB node can write ip address 127.0.0.1, or cmdifconfig check their ip premise is a visual tool (robo 3t client) can open you can open the local visualization the MongoDB
MongoPort = 27017 # port numbers are generally 27017
MongoDBname = 'mylove1' # document name
MongoItem = 'DouluodaluItem' #item name

---- (2)
piplines in

from pymongo import MongoClient  # 使用MongoClient连接mongo
from douluodalu.settings import Mongoip,MongoDBname,MongoPort,MongoItem   #从settings.py导入第一步配置的连接信息
class CrawldataToMongoPipline(object):
    def __init__(self):
        host = Mongoip      #主机
        port = MongoPort    #端口
        dbName=MongoDBname  #文档名
        client = MongoClient(host=host,port=port)    # 创建连接对象client
        db = client[dbName]                          # 使用文档dbName='mylove1'
        self.post = db[MongoItem]                  # 使用item MongoItem='DouluodaluItem'

    def process_item(self, item, spider):
        job_info = dict(item)                      # item转换为字典格式
        self.post.insert(job_info)                 # 将item写入mongo
        return item

---- (3) Finally, do not forget to open the pipeline in setting Open'douluodalu.pipelines.CrawldataToMongoPipline': 300,

Released four original articles · won praise 2 · Views 765

Guess you like

Origin blog.csdn.net/MYLOVEis77/article/details/104117633