Skip to content

AnsonZnl/NodeSpider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

NodeSpider

准备

下载request模块 使用它发起http请求
cnpm install request --save
下载cheerio模块 使用它解析DOM 可以把它看成Node 版的jQuery
cnpm install cheerio --save

爬取北京链家二手房房价

let cheerio= require('cheerio');
let request= require('request');

var url= 'https://bj.lianjia.com/ershoufang/'

request(url, (error, response, html)=>{
    if(!error && response.statusCode == 200){
        let $= cheerio.load(html)
        let unitPrice = $('.unitPrice>span').text();
        console.log(unitPrice);
    }
})

然后看结果:
61542249002_.pic.jpg

参考资料:

cheerio
request
手把手教你做爬虫---基于NodeJs

Releases

No releases published

Packages

No packages published