VBA 动态站点上的 Web 自动化

VBA Web Automation on a dynamic site

我正在尝试从此站点删除条形码所有者:http://gepir.gs1.org/index.php/search-by-gtin

由于最后一行,我收到 "Object doesnt support this property or method" 错误消息。我试图用 class 和标签提取它但失败了。

我正在尝试从动态 table 中提取公司名称。

Sub aa()

Dim ie As New SHDocVw.InternetExplorer
Dim doc As HTMLDocument
Dim aaa As Object
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer

ie.Visible = True
ie.navigate "gepir.gs1.org/index.php/search-by-gtin"

Do While ie.readyState <> READYSTATE_COMPLETE
Loop

Debug.Print ie.LocationName, ie.LocationURL

Set doc = ie.document

ie.document.forms("searchbygtin").elements("keyValue").Value = "685387379712"
ie.document.forms("searchbygtin").elements("method").Click

Debug.Print ie.document.getElementsBytag("tr")(7).innerText

End Sub

任何帮助都会很棒, 谢谢

您需要 TagName

Debug.Print ie.document.getElementsByTagName("tr")(7).innerText

虽然我得到了一个验证码,所以我怀疑你能用这种方式完成这个任务。 Selenium 和 IE 似乎都可以触发验证码,至少对我来说是这样。


如果没有验证码,我会按如下方式重写您的脚本(可能使用循环来确保 tr 元素存在):

Option Explicit

Public Sub GetLastChangeDate()
    Dim ie As New SHDocVw.InternetExplorer, doc As HTMLDocument
    Const URL = "gepir.gs1.org/index.php/search-by-gtin"

    With ie
        .Visible = True
        .navigate URL

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

        Set doc = .document

        Debug.Print .LocationName, .LocationURL

        doc.getElementById("keyValue").Value = "685387379712"
        doc.getElementById("submit-button").Click

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

        Debug.Print .document.getElementsByTagName("tr")(7).innerText
    End With
End Sub