Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA宏,用于在搜索后从google标题检索信息_Vba_Excel - Fatal编程技术网

VBA宏,用于在搜索后从google标题检索信息

VBA宏,用于在搜索后从google标题检索信息,vba,excel,Vba,Excel,我正在写一个宏,将进入谷歌搜索几个城市的县。到目前为止,我已经设法对正确的术语进行了宏搜索,但唯一的障碍是当我得到结果时。我不知道写什么来检索它们 当我进行搜索时,会得到以下结果: 我想做的是找回“萨福克郡”的线路,但我不知道该怎么做 有没有人有什么建议或者知道怎么做或者找什么?我已经试过检查这个项目,但没有结果 到目前为止,我的代码是这样的: Sub AutomateIE() Dim ie As InternetExplorer Dim City As String

我正在写一个宏,将进入谷歌搜索几个城市的县。到目前为止,我已经设法对正确的术语进行了宏搜索,但唯一的障碍是当我得到结果时。我不知道写什么来检索它们

当我进行搜索时,会得到以下结果:

我想做的是找回“萨福克郡”的线路,但我不知道该怎么做

有没有人有什么建议或者知道怎么做或者找什么?我已经试过检查这个项目,但没有结果

到目前为止,我的代码是这样的:

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对象库”和“Microsoft Internet控件”可用。在VB窗口中,转到工具->参考,并在该库旁边打一个复选标记(可能需要滚动才能找到它)

试试这个:

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

您需要确保“Microsoft HTML对象库”和“Microsoft Internet控件”可用。在VB窗口中,转到工具->参考,并在该库旁边打一个复选标记(可能需要滚动才能找到它)

试试这个:

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

您需要确保“Microsoft HTML对象库”和“Microsoft Internet控件”可用。在VB窗口中,转到工具->参考,并在该库旁边打一个复选标记(可能需要滚动才能找到它)

试试这个:

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

您需要确保“Microsoft HTML对象库”和“Microsoft Internet控件”可用。在VB窗口中,转到工具->参考,并在该库旁边打一个复选标记(可能需要滚动才能找到它)

试试这个:

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


HTMLDocument来自什么参考?啊,对不起-我相信来自“Microsoft HTML对象库”。就是它。我在dd=doc.getElementsByClassName(“_eF”)(0)处得到一个对象variabl或with block not set error。innerText,但在调试中等待几秒钟后该行就会运行。这可能是一个timming问题吗?可能是-我对HTML解析还是很陌生,但我确实删除了一行让脚本等待了一段时间的内容。我会用它更新我的代码看看是否有用。嗨,布鲁斯!感谢这一点,我目前遇到了一个编译错误:用户定义的错误类型未定义。这是Dim IE作为新的InternetExplorer在第一行代码中出现的。有什么想法可以解决这个问题吗?HTMLDocument来自什么参考?啊,对不起,我相信来自“Microsoft HTML对象库”。就是这样。我在dd=doc.getElementsByClassName(“_eF”)(0)处得到一个对象variabl或with block not set error。innerText,但在调试中等待几秒钟后该行就会运行。这可能是一个timming问题吗?可能是-我对HTML解析还是很陌生,但我确实删除了一行让脚本等待了一段时间的内容。我会用它更新我的代码看看是否有用。嗨,布鲁斯!感谢这一点,我目前遇到了一个编译错误:用户定义的错误类型未定义。这是Dim IE作为新的InternetExplorer在第一行代码中出现的。有什么想法可以解决这个问题吗?HTMLDocument来自什么参考?啊,对不起,我相信来自“Microsoft HTML对象库”。就是这样。我在dd=doc.getElementsByClassName(“_eF”)(0)处得到一个对象variabl或with block not set error。innerText,但在调试中等待几秒钟后该行就会运行。这可能是一个timming问题吗?可能是-我对HTML解析还是很陌生,但我确实删除了一行让脚本等待了一段时间的内容。我会用它更新我的代码看看是否有用。嗨,布鲁斯!感谢这一点,我目前遇到了一个编译错误:用户定义的错误类型未定义。这是Dim IE作为新的InternetExplorer在第一行代码中出现的。有什么想法可以解决这个问题吗?HTMLDocument来自什么参考?啊,对不起,我相信来自“Microsoft HTML对象库”。就是这样。我在dd=doc.getElementsByClassName(“_eF”)(0)处得到一个对象variabl或with block not set error。innerText,但在调试中等待几秒钟后该行就会运行。这可能是一个timming问题吗?可能是-我对HTML解析还是很陌生,但我确实删除了一行让脚本等待了一段时间的内容。我会用它更新我的代码看看是否有用。嗨,布鲁斯!感谢这一点,我目前遇到了一个编译错误:用户定义的错误类型未定义。作为新的InternetExplorer,Dim IE的第一行代码中出现了这个问题。有什么办法解决这个问题吗?