• 数据用


    https://segmentfault.com/a/1190000008745531

    var cheerio = require('cheerio');
    var http = require('http');
    var iconv = require('iconv-lite');
    //https://segmentfault.com/a/1190000008745531
    //var url = 'http://www.ygdy8.net/html/gndy/dyzz/index.html';
    var url = "http://nj.rent.house365.com/district_i1/dl_x1.html";
    http.get(url, function(sres) {
        var chunks = [];
        sres.on('data', function(chunk) {
            chunks.push(chunk);
        });
        // chunks里面存储着网页的 html 内容,将它zhuan ma传给 cheerio.load 之后
        // 就可以得到一个实现了 jQuery 接口的变量,将它命名为 `$`
        // 剩下就都是 jQuery 的内容了
        sres.on('end', function() {
            var titles = [];
            //由于咱们发现此网页的编码格式为gb2312,所以需要对其进行转码,否则乱码
            //依据:“<meta http-equiv="Content-Type" content="text/html; charset=gb2312">”
            var html = iconv.decode(Buffer.concat(chunks), 'gb2312');
            var $ = cheerio.load(html, {decodeEntities: false});
            $('.info .name a').each(function (idx, element) {
                var $element = $(element);
                console.log($element.attr("href"),$element.text());
                titles.push({
                    title: $element.text()
                })
            })
            //console.log(titles);
        });
    });
    

      

  • 相关阅读:
    C#如何通过NCO3.0来连接SAP并调用SAP中的RFC
    .Net连接到SAP【转载】
    将博客搬至CSDN
    Apache Flume 简介
    日志收集以及分析:Splunk
    《淘宝技术这十年》读后感
    python参考手册--第9章
    Hadoop将过时了?
    pythn BeautifulSoup
    Python性能鸡汤
  • 原文地址:https://www.cnblogs.com/cnchengv/p/8605728.html
Copyright © 2020-2023  润新知