我正在尝试右键单击Google Maps页面,到目前为止,我已经能够创建对象ie
,导航到该页面并搜索特定的地址。
但是在下一步中,我必须单击地址标记 (蓝点)
单击后,我要从选项中选择What's Here
。
选择后,我使用
ie.document.getElementsByClassName("link-like widget-reveal-card-lat-lng")(0).innerText
获取该地点的坐标。
代码:
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://www.google.com/maps"
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Application.Wait DateAdd("s", 1, Now)
ie.document.getElementById("searchboxinput").Value = "Signature Tower GurGaon"
ie.document.getElementById("searchbox-searchbutton").Click
MsgBox "After Manually clicking What's Here, press ok"
基本上我想自动化该手册部分。右键单击需要单击哪些元素?如何确定单击位置。
备用:
刚刚发现,那些经纬度也是a href by
的一部分ie.document.getElementsByClassName("gb_9d gb_2 gb_ob")(0).href
因此无需右键单击。
但是我仍然想知道如何右键单击它。
答案 0 :(得分:2)
请注意,您可以将搜索词直接放入第一个导航栏中。
IE.navigate "https://www.google.com/maps" & "/search/Signature Tower GurGaon"
您的等待循环应检查.Busy
和.ReadyState
Do While IE.Busy Or IE.ReadyState <> 4
您已经发现坐标在源代码中
Option Explicit
Public Sub Test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.google.com/maps" & "/search/Signature Tower GurGaon"
Do While IE.Busy Or IE.ReadyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Application.Wait DateAdd("s", 1, Now)
Dim GetLocation As String
GetLocation = IE.document.getElementsByClassName("gb_9d gb_2 gb_ob")(0).href
GetLocation = Right$(GetLocation, Len(GetLocation) - InStr(1, GetLocation, "%40") - 2)
GetLocation = Left$(GetLocation, InStr(1, GetLocation, "&") - 1)
Dim Location() As String
Location = Split(GetLocation, "%2C")
Debug.Print "Lat", Location(0)
Debug.Print "Lon", Location(1)
Debug.Print "zoom", Location(2)
End Sub
会导致
Lat 28.4636862
Lon 77.054257
zoom 16z