简体   繁体   中英

How can I pull data from website using vba

I am new at vba coding to pull data from website so generally, I use this code to connect and check item to pull data from website but this code cannot check data via watch in vba with my firm webapp. it show nothing when I add watch to the class so what should I do. HTML Code from my firm webapp 1

HTML Code from my firm webapp 2

Sub Connect_web()

    Dim ie As InternetExplorer
    Dim doc As HTMLdocument
    Dim ele As IHTMLElement
    Dim col As IHTMLElementCollection
    Dim ele_tmp As IHTMLElement

    Set ie = New InternetExplorer
    URL = "" ' Cannot provide
    ie.Visible = True
    ie.navigate URL

    Do While ie.readyState <> READYSTATE_COMPLETE

        Application.StatusBar = "Loading Page..."
        DoEvents

        End If

    Loop

    Set doc = ie.Document
    Set ele = doc.getElementByClassName("GDB3EHGDHLC")

end sub

Let's start with four things:

1) Instead of .Navigate use .Navigate2

2) Use a proper wait

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

3) Correct the syntax of your Set ele line. You are using ByClassName which returns a collection and therefore is plural. You are missing the s at the end of element .

As you have declared ele as singular (element), perhaps first set the collection into a separate variable and index into that collection.

Dim eles As Object, ele As Object
Set eles  = doc.getElementsByClassName("GDB3EHGDHLC")
Set ele = eles(0)

4) You should always use id over other attributes, if possible, as id is usually quicker for retrieval. There is an id against that class name in your image (highlighted element). I am not going to try and type it all out. Please share your HTML using the snippet tool, by editing your question, so we can relate to your html in answer easily.

Set ele = doc.getElementById("gwt-debug-restOfIdStringGoesHere")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM