豆瓣電影top250爬取並儲存在MongoDB裡

來源:互聯網
上載者:User

標籤:gre   code   分享   建立項目   ring   count   sort   刪除   start   

首先回顧一下MongoDB的基本操作:

 

資料庫,集合,文檔db,show dbs,use 資料庫名,drop 資料庫db.集合名.insert({})db.集合名.update({條件},{$set:{}},{multi:true})db.集合名.remove({條件})db集合名.find({條件},{投影}).limit().skip().sort().count().distinct()資料庫 增加 修改 刪除 查詢mysqlinsert update delete selectredissetsetdelgetmongodbinsertupdateremovefind,aggregate

string
hash
list
set
zset

增加
mysql:insert into 表名(列) values(值)
mongo:db.集合名.insert({})

修改:
mysql:update 表名 set 列=值 where 條件
mongo:db.集合名.update({條件},{值$set},{是否修改多條})

刪除:
mysql:delete from 表名 where ....
mongo:db.集合名.remove({條件},{是否刪除多條})

查詢:
db.stu.find({},{})
比較子,邏輯運算子,$where
limit(),skip(),sort(),count(),distinct()

 

 

 

 

 

 

首先使用xpath提取出要爬取的資訊:我們這個項目需要爬取的資訊有:標題,資訊,評分,簡介

 

第一頁連結:https://movie.douban.com/top250

第二頁連結:https://movie.douban.com/top250?start=25&filter=

第三頁連結:https://movie.douban.com/top250?start=50&filter=

規律:https://movie.douban.com/top250?start=\d+&filter=

 

標題://a/span[@class="title"][1]

資訊://div[@class="bd"]/p[1]/text()

評分://div[@class="star"]/span[2]/text()

簡介://span[@class="inq"]/text()

 

 

然後使用sscrapy startproject douban   建立項目

              sscrapy genspider dopuban  movie.douban.com

然後依次編寫下面的檔案:

items.pydoubanmovie.pysettings.pypipelines.py

 

 

 

      

豆瓣電影top250爬取並儲存在MongoDB裡

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.