爬取大众点评-各大城市的医疗美容板块数据

2021/10/23 23:41:00

本文主要是介绍爬取大众点评-各大城市的医疗美容板块数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

(function () {
    var list = document.querySelectorAll("#shop-all-list>ul>li ");
    var city = document.querySelector(".J-current-city").innerText;
    var page = 0;
    try {
        page = document.querySelector(".page>a.cur").innerText;
    } catch (err) {
        console.log(err);
    }
    var region = "全市";
    try {
        region = document.querySelector("#region-nav>a.cur").getAttribute("data-click-title");
    } catch (err) {
        console.log(err);
    }
    var datas = '\uFEFF';
    datas = datas + "code,name,address,city,region\r\n";
    for (j = 0; j < list.length; j++) {
        var div = list[j];
        var d = div.querySelector(".operate.J_operate.Hide");
        var a = d.querySelector("a.o-nearby.J_o-nearby");
        var name = a.getAttribute("data-sname");
        var address = "";//a.getAttribute("data-address");
        var code = div.querySelector(".txt>.tit>a").getAttribute("href").replace("http://www.dianping.com/shop/", "");
        var data = '"' + code + '","' + name + '","' + address + '","' + city + '","' + region + '"\r\n';
        datas = datas + data;
    }
    var filename = city + "_" + region + "_" + page + ".csv";
    var a = document.createElement('a');
    var blob = new Blob([datas], {
        type: "text/csv;charset=utf-8;"
    });
    a.download = filename;
    a.href = URL.createObjectURL(blob);
    a.click();
    URL.revokeObjectURL(blob);
})();



这篇关于爬取大众点评-各大城市的医疗美容板块数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程