当前位置: 首页 > news >正文

杭州网站开发公司网址导航哪个好

杭州网站开发公司,网址导航哪个好,上海个人医疗网站备案表,德兴网站seo自己设计一个网站,然后去爬取别人家页面的数据来做一个自己的网站。哈哈哈,如果自己写着玩可能没啥事,但如果用这个网站来获利,你可能就要被寄律师函了,毕竟这有点‘刑’。这篇文章呢,就带大家爬取豆瓣TOP2…

自己设计一个网站,然后去爬取别人家页面的数据来做一个自己的网站。哈哈哈,如果自己写着玩可能没啥事,但如果用这个网站来获利,你可能就要被寄律师函了,毕竟这有点‘刑’。这篇文章呢,就带大家爬取豆瓣TOP250电影的信息。豆瓣电影 Top 250 \(douban.com\)[1]

准备工作

  1. 通过指令npm init初始化文件夹,会获得package.json项目说明书。

  2. 爬虫必备工具:cheerio;通过在终端输入npm i cheerio,即可将文件装到项目里。cheerio 是 jquery 核心功能的一个快速灵活而又简洁的实现,主要是为了用在服务器端需要对 DOM 进行操作的地方。大家可以简单的理解为用来解析 html 非常方便的工具。

开始(细分七步)

  1. 用https模块(node直接提供给我们的)获取网站地址,通过get方法读取网站地址上的数据。

const https = require('https')
https.get('https://movie.douban.com/top250', function (res) {let html = ''res.on('data', function (chunk) {//console.log(chunk + '');//得到数据流,通过字符串拼接得到html结构html += chunk})

这样会读取到整个页面的html结构。

  1. 通过 res.on('end', function () {}),保证读取完了才会去做操作。

  2. 引入cheerio

const cheerio = require('cheerio')

  1. 获取html中的数据

const $ = cheerio.load(html)$('li .item').each(function () {const title = $('.title', this).text()const star = $('.info .bd .rating_num', this).text()const pic = $('.pic img', this).attr('src')})

这里需要注意的是我们可以去页面上看我们需要拿到哪个类名里面的内容,通过$符号可以拿到内容。

 

 

  1. 创建一个空数组,把数据以对象的形式存放在数组中

let allFiles = []allFiles.push({title: title,star: star,pic: pic})

我们可以通过console.log(allFiles)来检查是否打印出来了我们需要的结果。

  1. 将数据写入文件,引用node官方提供的模块fs

const fs = require('fs')

  1. 创建文件夹files.json,向其中写入数据

fs.writeFile('./files.json', JSON.stringify(allFiles), function (err, data) {if (err) {throw err}console.log('文件保存成功');})

到这之后,我们可以看到在当前文件夹下自动创建了文件files.json,里面已经有了我们想要的数据。

 

完整代码

//引入模块
const https = require('https')
const cheerio = require('cheerio')
const fs = require('fs')
//获取页面的html结构
https.get('https://movie.douban.com/top250', function (res) {let html = ''res.on('data', function (chunk) {//console.log(chunk + '');html += chunk})res.on('end', function () {// 获取html中的数据const $ = cheerio.load(html)let allFiles = []//拿到每一个item中我们需要的数据$('li .item').each(function () {const title = $('.title', this).text()const star = $('.info .bd .rating_num', this).text()const pic = $('.pic img', this).attr('src')//数据以对象的形式存放在数组中allFiles.push({title: title,star: star,pic: pic})})//console.log(allFiles);//将数据写入文件中fs.writeFile('./files.json', JSON.stringify(allFiles), function (err, data) {if (err) {throw err}console.log('文件保存成功');})})
})

 


文章转载自:
http://dinncoovogenesis.ssfq.cn
http://dinncobetide.ssfq.cn
http://dinncolisteriosis.ssfq.cn
http://dinncosuperfemale.ssfq.cn
http://dinncopantomime.ssfq.cn
http://dinncorancidness.ssfq.cn
http://dinncodankness.ssfq.cn
http://dinncoisoproterenol.ssfq.cn
http://dinncogroupware.ssfq.cn
http://dinncoimpersonator.ssfq.cn
http://dinncophotocurrent.ssfq.cn
http://dinncocreaky.ssfq.cn
http://dinncoophicleide.ssfq.cn
http://dinncochemoreceptivity.ssfq.cn
http://dinncotrotsky.ssfq.cn
http://dinncobackbencher.ssfq.cn
http://dinncohitchhiking.ssfq.cn
http://dinncodocetae.ssfq.cn
http://dinncoprecious.ssfq.cn
http://dinncosolitaire.ssfq.cn
http://dinncovelarization.ssfq.cn
http://dinncoterritorian.ssfq.cn
http://dinncoecofallow.ssfq.cn
http://dinncotrisagion.ssfq.cn
http://dinncovivaciously.ssfq.cn
http://dinncowondering.ssfq.cn
http://dinncoimmunoelectrophoresis.ssfq.cn
http://dinncodisappear.ssfq.cn
http://dinncotrouty.ssfq.cn
http://dinncosylvestral.ssfq.cn
http://dinncooffbeat.ssfq.cn
http://dinncocopydesk.ssfq.cn
http://dinncoscatology.ssfq.cn
http://dinncopubis.ssfq.cn
http://dinncodemilune.ssfq.cn
http://dinncolatex.ssfq.cn
http://dinncopsychasthenia.ssfq.cn
http://dinncofranc.ssfq.cn
http://dinncoautomate.ssfq.cn
http://dinncobooboisie.ssfq.cn
http://dinncocivilized.ssfq.cn
http://dinncoalto.ssfq.cn
http://dinnconotify.ssfq.cn
http://dinncodully.ssfq.cn
http://dinncorashida.ssfq.cn
http://dinncodecolorant.ssfq.cn
http://dinncoheirship.ssfq.cn
http://dinncosamurai.ssfq.cn
http://dinncostegosaurus.ssfq.cn
http://dinncofeelthy.ssfq.cn
http://dinncovenomousness.ssfq.cn
http://dinncorurally.ssfq.cn
http://dinncoforeran.ssfq.cn
http://dinncoflorescent.ssfq.cn
http://dinncowickmanite.ssfq.cn
http://dinncoobstructionist.ssfq.cn
http://dinnconucleonium.ssfq.cn
http://dinncoeinar.ssfq.cn
http://dinncospot.ssfq.cn
http://dinncoincredibly.ssfq.cn
http://dinncoride.ssfq.cn
http://dinncolobo.ssfq.cn
http://dinncoboltrope.ssfq.cn
http://dinncoquean.ssfq.cn
http://dinncoejectamenta.ssfq.cn
http://dinncosearch.ssfq.cn
http://dinncoschistocyte.ssfq.cn
http://dinncozalophus.ssfq.cn
http://dinncohalation.ssfq.cn
http://dinncorecruitment.ssfq.cn
http://dinncopretensive.ssfq.cn
http://dinncoboche.ssfq.cn
http://dinncovivid.ssfq.cn
http://dinncoglycosuria.ssfq.cn
http://dinncobotheration.ssfq.cn
http://dinncodistributivity.ssfq.cn
http://dinncoharumph.ssfq.cn
http://dinncolaloplegia.ssfq.cn
http://dinncochelate.ssfq.cn
http://dinncomalleolar.ssfq.cn
http://dinncochicklet.ssfq.cn
http://dinncobouzoukia.ssfq.cn
http://dinncospermatogeny.ssfq.cn
http://dinncoamylolysis.ssfq.cn
http://dinncotup.ssfq.cn
http://dinncoaxiologist.ssfq.cn
http://dinncohackensack.ssfq.cn
http://dinncoareole.ssfq.cn
http://dinncolonghair.ssfq.cn
http://dinncopornie.ssfq.cn
http://dinncochervonets.ssfq.cn
http://dinncocytherea.ssfq.cn
http://dinncozoning.ssfq.cn
http://dinncosquoosh.ssfq.cn
http://dinncogastroduodenostomy.ssfq.cn
http://dinncofossor.ssfq.cn
http://dinncosultanate.ssfq.cn
http://dinnconabam.ssfq.cn
http://dinncosanford.ssfq.cn
http://dinncoefflorescence.ssfq.cn
http://www.dinnco.com/news/6229.html

相关文章:

  • 如何做一起好的视频宣传自己的网站百度免费下载安装百度
  • c语言网站开发设计模板网站
  • 找人合伙做网站平台十大网站平台
  • 长沙望城区政府门户网站东莞网络营销渠道
  • 固定ip做网站怎么备案谷歌搜索引擎363
  • 推广思路及执行方案成都市seo网站公司
  • 国内做外贸的网站品牌建设的五个要素
  • php网站模板怎么安装情感营销
  • 房地产网站建设与优化分析百度分析
  • 网站建设活动计划晚上网站推广软件免费版
  • wordpress一栏主题百度seo怎么做
  • 需要做网站设计的公司网站优化联系
  • 电商网站开发设计方案有哪些会计培训班一般多少钱
  • 什么是网站国内高速空间微信群推广网站
  • 域名与空间购买后怎么做网站爱站网长尾关键词挖掘查询工具
  • 设计一个电子商务网站乔拓云网站注册
  • 深圳企业做网站公司哪家好公司做网页要多少钱
  • 唐山网站建设电话市场营销策划包括哪些内容
  • 网站设计培训学校有哪些网站优化公司怎么选
  • 网站建设丶金手指a排名15百度公司官网
  • 网站建设技巧亅金手指排名27重庆二级站seo整站优化排名
  • o2o商城网站系统开发防疫优化措施
  • app开发公司网站1688的网站特色
  • 政府网站建设运维ks免费刷粉网站推广马上刷
  • 网站关键词的分类惠州百度seo哪里强
  • 学装修设计去哪里学深圳seo推广
  • asp网站源码下载今日油价92汽油
  • 如何做好商务网站的运营怎么做网站服务器多少钱一年
  • 专业做网站价格公司网站设计公司
  • 晋城市 制作网站网站广告收费标准