利用Excel将百度地图搜索结果导出

1、打开Excel文件(或新建一个Excel文件),在菜单栏中找到“开发工具”→“宏”,创建宏,应该也叫VBA程序(截图以office 2016版本为例,其他版本只要能找到宏添加运行即可)。


2、点击创建,在打开的代码编辑框里,粘贴以下代码:

代码:

Sub baiduMap()

    Dim url, html, js

    Cells.ClearContents

    br = [{"店名","地址","电话"}]

    Range("a1:c1") = br

    url = ""

    Set html =CreateObject("htmlfile")

    Set js =CreateObject("scriptcontrol")

    js.Language = "jscript"

    For p = 1 To 5

        WithCreateObject("msxml2.xmlhttp")

            url ="http://map.baidu.com/?newmap=1"

            url = url &"&reqflag=pcmap"

            url = url &"&biz=1"

            url = url &"&from=webmap"

            url = url &"&qt=s"

            url = url &"&from=webmap"

            url = url &"&c=257"

            url = url &"&pl_data_type=cater"

            url = url & "&pl_sub_type=餐饮"

            url = url &"&pl_price_section=0%2C%2B"

            url = url &"&pl_sort_type=data_type"

            url = url &"&pl_sort_rule=0"

            url = url &"&pl_discount2_section=0%2C%2B"

            url = url &"&pl_groupon_section=0%2C%2B"

            url = url &"&pl_cater_book_pc_section=0%2C%2B"

            url = url &"&pl_ticket_book_flag_section=0%2C%2B"

            url = url &"&pl_movie_book_section=0%2C%2B"

            url = url &"&pl_business_type=cater"

            url = url &"&pl_business_id="

            url = url &"&pl_activity_gwj_section=0%2C%2B"

            url = url &"&wd=餐饮"

            url = url &"&pn=1"

            url = url &"&db=0"

            url = url &"&wd2="

            url = url & "&sug=0"

            url = url &"&da_src=pcmappg.poi.page"

            url = url &"&on_gel=1"

            url = url &"&src=7"

            url = url &"&gr=3"

 

            url = url &"&l=12"

            url = url &"&addr=0"

            url = url &"&nn=" & (p - 1) * 10

            url = url &"&tn=B_NORMAL_MAP"

            url = url &"&ie=utf-8"

            url = url &"&t=1412423900383"

            .Open "get", url, False

            .send

            js.addcode ("suwenkai = "& .responsetext)

 

            slen =js.eval("suwenkai.content.length") - 1

            For i = 0 To slen

                n = n + 1

                Cells(n + 1, 1) =js.eval("suwenkai.content[" & i & "].name")

                Cells(n + 1, 2) =js.eval("suwenkai.content[" & i & "].addr")

                Cells(n + 1, 3) =js.eval("suwenkai.content[" & i & "].tel")

            Next

        End With

    Next

End Sub

蓝色代码注释

1、    br =[{"名称","地址","电话"}]:创建在excel的目录,如


2、    For p= 1 To 5:表示从百度地图中取第1页至第5页的搜索结果,根据具体情况设置最大读取页数。例如:

3、    url =url & "&c=257":城市代码设置,当前设置城市为广州市  ,例如北京的城市代码为131,将c=257设置为c=131即可。中国城市代码对应在同文件夹下的<<城市代码.xlsx>>。

4、    url =url & "&pl_sub_type=餐饮"

url = url & "&pl_sub_type=餐饮":

关键字设置:

例如要把关键字设置为“设计院”,将“餐饮”,改为“设计院”即可。


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭