|
楼主 |
发表于 2015-12-6 14:23
|
显示全部楼层
YZC51 发表于 2015-12-6 09:55
经纬度
Cells(n + 1, 6) = CallByName(jsonItem, "diPointX", VbGet) & "/" & CallByName(jsonItem, "diPo ...
是这样吗大神,但导出的结果不是经纬度啊
- Sub BaiDuMap()
- Dim winhttp, URL, arr, i, j, p, t, objSC, strJSON, objJSON, pages, n, strFunc, jsonItem
- Sheet1.Cells.Clear
- Set winhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
- Application.ScreenUpdating = False
- Application.DisplayStatusBar = True
- With winhttp
- For i = 1 To 10
- URL = "http://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&pcevaname=pc2&da_par=baidu&from=webmap&qt=con&from=webmap&c=179&wd=%E6%AF%8D%E5%A9%B4%E5%BA%97&pn=" & i - 1 & "&db=0&wd2=&sug=0&da_src=pcmappg.poi.page&on_gel=1&src=7&gr=3&b=(13333343.77,3501052.46;13433759.77,3528380.46)&l=12&addr=0&nn=" & (i - 1) * 10 & "&tn=B_NORMAL_MAP&ie=utf-8&t=1423980798053"
- .Open "GET", URL, False
- .setRequestHeader "Connection", "Keep-Alive"
- .send
- t = UToGB(.responsetext)
- strJSON = Split(Split(t, """content"":")(1), ",""current_city")(0)
- Set objSC = CreateObject("ScriptControl")
- objSC.Language = "JScript"
- strFunc = "function getjson(s) { return eval('(' + s + ')'); }"
- objSC.AddCode strFunc
- Set objJSON = objSC.CodeObject.getjson(strJSON)
- For Each jsonItem In objJSON
- On Error Resume Next
- n = n + 1
- Cells(n, 1) = CallByName(jsonItem, "name", VbGet)
- Cells(n, 2) = CallByName(jsonItem, "addr", VbGet)
- Cells(n, 3) = CallByName(jsonItem, "tel", VbGet)
- Cells(n, 6) = CallByName(jsonItem, "diPointX", VbGet) & "/" & CallByName(jsonItem, "diPointY", VbGet)
- Next
- Next
- End With
- Set objSC = Nothing
- Set objJSON = Nothing
- Set jsonItem = Nothing
- Set winhttp = Nothing
- Application.StatusBar = False
- Application.ScreenUpdating = True
- End Sub
- Function UToGB(ByVal str1 As String)
- Dim i, y, arr1(), arr2(), ireg As Object, imch As Object, mch As Object
- Set ireg = CreateObject("vbscript.regexp")
- ireg.Global = True
- ireg.Pattern = "\\u\w{4}"
- Set imch = ireg.Execute(str1)
- For Each mch In imch
- y = y + 1
- ReDim Preserve arr1(1 To y)
- ReDim Preserve arr2(1 To y)
- arr1(y) = ChrW(CLng(Replace(mch.Value, "\u", "&h")))
- arr2(y) = mch.Value
- Next
- For i = 1 To UBound(arr1)
- str1 = Replace(str1, arr2(i), arr1(i))
- Next
- UToGB = str1
- Set ireg = Nothing
- End Function
复制代码 |
|