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

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

上一篇:8086汇编语言程序设计--已知有几个元素存放在以BUF为首址的字节存贮区中,试统计其中正元素的个数。


下一篇:uniapp封装get和post请求