Search code examples
htmlexcelvbaweb-scrapingwebautomation

VBA Web Automation on a dynamic site


I am trying to scrap barcode owners from this site : http://gepir.gs1.org/index.php/search-by-gtin

I am receiving "Object doesnt support this property or method" error msg because of the final line. I tried to extract it with class and tag but failed.

I am trying to extract the company name from the dynamic 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

Any help would be great, Thanks


Solution

  • You need TagName

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

    I get a captcha though so I doubt you can complete this task in this way. Selenium and IE both seem to trigger the captcha, at least for me.


    If not for the captcha I would re-write your script as follows (perhaps with a loop to make sure tr element is present):

    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