js获取最新最完整省市区数据

 

数据地址:http://www.mca.gov.cn/article/sj/xzqh/2020/

js获取最新最完整省市区数据_第1张图片

var str = "insert into tablename (code, name)values"
Array.from($("tbody").children).map((tr, index)=>{
    if(index>2 && index<3216){
        console.log(tr.children[1].innerText.trim(), tr.children[2].innerText.trim())
        if(tr.children[1]){
            str = str + "('" + tr.children[1].innerText.trim() +"','"+tr.children[2].innerText.trim()+"'),"
        }
    }
})
console.log(str.substring(0,str.length-1))

组成数组,放入laravel seeder运行:

   var str = "";
    Array.from($("tbody").children).map((tr, index)=>{
        if(index>2 && index<3216){
            console.log(tr.children[1].innerText.trim(), tr.children[2].innerText.trim())
            if(tr.children[1]){
                str = str + "['code'=>'" + tr.children[1].innerText.trim() +"','name'=>'"+tr.children[2].innerText.trim()+"'],"
            }
        }
    })
    console.log(str.substring(0,str.length-1))

 

你可能感兴趣的:(js)