其他分享
首页 > 其他分享> > 爬取大众点评-各大城市的医疗美容板块数据

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

作者:互联网

(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);
})();

标签:city,region,点评,爬取,美容,querySelector,var,document,datas
来源: https://blog.csdn.net/weixin_46435234/article/details/120928083