【问题标题】:Get the address with google to excel用google获取地址到excel
【发布时间】:2016-01-04 16:17:40
【问题描述】:

我正在尝试导航到谷歌,然后写一个类似“Y 州超市 X”的地方,然后在谷歌中出现市场照片和下面的地址。

所以我希望在 google 中设置商店而不是获取地址并将其设置为 excel 中的单元格。

我唯一的代码:

Sub search()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
With IE
    .Visible = False
    .Navigate ("https://www.google.com")
While .Busy Or .readyState <> 4: DoEvents: Wend
.document.getElementById("lst-ib").Value = "vida" ' ID of TextBox of google
.document.all("sblsbb").Click ' ID of the search button of google
End With

结束子

但我得到的错误是最后一行。

谢谢

【问题讨论】:

  • 你需要检查 IE 是不是忙,并且是 READY,VBA 不在乎 IE 正在加载 google
  • ' 在浏览器忙碌或仍在加载时循环播放 While objIE.Busy 或 objIE.readyState READYSTATE_COMPLETE DoEvents Wend
  • 然后设置你的文本框,然后做同样的事情,但是找到搜索按钮和 btn.Click 应该做搜索。
  • 还是出错了,最后两行
  • .document.getElementsByClassName("lsb")(0).click 是方式,你需要做一点调查,上面是包含按钮的div的名称

标签: excel vba web web-scraping


【解决方案1】:

“Vida”即使在首页也不一定会带回商店。

这将为您进行搜索,然后您需要决定下一步该做什么。

Option Explicit
Public Sub HitThatSearchButton()
    Dim ie As New InternetExplorer
    Const URL As String = "https://www.google.com/"
    With ie
        .Visible = True
        .navigate URL
        While .Busy Or .readyState < 4: DoEvents: Wend

        .document.querySelector("#lst-ib").Value = "Vida"
        .document.querySelector("input[value='Google Search']").Click

        While .Busy Or .readyState < 4: DoEvents: Wend

        Stop                                     '<== Delete me
        .Quit
    End With
End Sub

【讨论】:

    猜你喜欢
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 2016-11-23
    • 2016-08-21
    相关资源
    最近更新 更多