+ Reply to Thread
Results 1 to 5 of 5

Extracting a value from a webpage

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Extracting a value from a webpage

    Good day - I am sure this was addressed numerous times, but I am frustrated I tried all possible ways and still cant get it to work.

    I am trying to scrape a value from a website which has the following code:

    CODE.png

    I need to extract only 169.23

    This is my code which is not working:

    Sub ImportCurrentPrice2()
    
    Dim appIE As Object
    Set appIE = CreateObject("internetexplorer.application")
    
    Visible = True
    
    With appIE
        .Navigate "https://finance.google.com/finance?q=AAPL"
        .Visible = False
    End With
    
    Do While appIE.Busy
        DoEvents
    Loop
    
    
    
    Set allRowOfData = appIE.document.getElementsByClassName("hilite")
    
    Dim myValue As String: myValue = allRowOfData.Cells(4).innerHTML
    
    appIE.Quit
    Set appIE = Nothing
    
    Range("A1").Value = myValue
    
    
    End Sub
    This returns an error.

    Any suggestion how code above needs to be modified?

    Thank You,
    Last edited by gtg430i; 12-31-2017 at 06:02 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,052

    Re: Extracting a value from a webpage

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extracting a value from a webpage

    getElementsByClassName returns an array like nodes, so you need to specify the postion of the index you want to return.

    For instance
    appIE.document.getElementsByClassName("hilite")(4).innertext
    My guess would be

    appIE.document.getElementsByClassName("rgt")(0).innerHtml
    Last edited by AliGW; 12-31-2017 at 09:38 AM. Reason: Code tags!!!

  4. #4
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Extracting a value from a webpage

    Hello - I have already fixed this issue.

    Thank you for your efforts.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,052

    Re: Extracting a value from a webpage

    Yes - that is why post #3 was allowed - you have complied with the moderation request - thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extracting webpage source code using VBE
    By rolex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2017, 02:24 PM
  2. Help Needed: Extracting data from webpage
    By Elangovan89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 08:43 AM
  3. Extracting table from webpage
    By amber_skanpur in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2014, 10:12 AM
  4. I need some help extracting data from a specified webpage
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 07:35 PM
  5. Extracting Data from Webpage
    By Kevin.Antony in forum Excel General
    Replies: 4
    Last Post: 01-06-2012, 02:38 PM
  6. Extracting data from imported Webpage VBA
    By pnaquin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2011, 02:10 PM
  7. Extracting data from webpage
    By Gramzon in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-22-2009, 12:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1