+ Reply to Thread
Results 1 to 5 of 5

Webscraping data from Yahoo Finance

Hybrid View

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Webscraping data from Yahoo Finance

    Hi,

    From the following link I would like to extract Sector and Industry. Can anyone help me out with the code.

    https://finance.yahoo.com/quote/AMZN/profile?p=AMZN
    Cheers!
    Deep Dave

  2. #2
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,152

    Re: Webscraping data from Yahoo Finance

    Try this;

    Sub Test()
    '   Haluk - 15/03/2020
    '   [email protected]
    '
        Dim HTTP As Object, HTML As Object, i As Integer
        
        myURL = "https://finance.yahoo.com/quote/AMZN/profile?p=AMZN"
        
        Set HTML = CreateObject("HTMLFILE")
        Set HTTP = CreateObject("MSXML2.XMLHTTP")
        
        HTTP.Open "GET", myURL, False
        HTTP.send
        
        HTML.body.innerHTML = HTTP.responseText
        
        Set objCollection = HTML.getElementsByTagName("span")
        
        i = 0
        Do While i < objCollection.Length
          If objCollection(i).classname = "Fw(600)" Then
             If objCollection(i).getAttribute("data-reactid") = 21 Then
                xSector = objCollection(i).innerText
             ElseIf objCollection(i).getAttribute("data-reactid") = 25 Then
                xIndustry = objCollection(i).innerText
             ElseIf objCollection(i).getAttribute("data-reactid") = 29 Then
                xEmployees = objCollection(i).innerText
             End If
          End If
          i = i + 1
        Loop
        
        MsgBox "Sector = " & xSector & vbCrLf & _
               "Industry = " & xIndustry & vbCrLf & _
               "Num. of Employees = " & xEmployees
        
        Set HTML = Nothing
        Set HTTP = Nothing
    End Sub

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Re: Webscraping data from Yahoo Finance

    Hi Haluk,

    Thank you very much.. It helped a lot, and sorry for the late reply..

    Cheers!

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Webscraping data from Yahoo Finance

    Hi,

    Did you know about the newer Data Types built into Excel that might give you what you want? See:
    https://www.excelforum.com/excel-pro...o-finance.html
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Re: Webscraping data from Yahoo Finance

    Quote Originally Posted by MarvinP View Post
    Hi,

    Did you know about the newer Data Types built into Excel that might give you what you want? See:
    https://www.excelforum.com/excel-pro...o-finance.html
    Hi MarvinP,

    Thanks for the reply.. However that link is pointing to this Post.

+ 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. VBA webscraping Yahoo finance
    By martijnrikkert in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2017, 08:46 AM
  2. Extracting Stock Data from Yahoo Finance
    By Alex Fernandes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2013, 05:20 AM
  3. Help downloading yahoo finance data
    By ecelaras in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2013, 02:23 PM
  4. Getting real time stock quotes from google finance / yahoo finance in excel
    By Navin Agrawal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2012, 12:41 PM
  5. Download data from Yahoo Finance
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2010, 10:21 AM
  6. finance.yahoo historical data
    By tinybears in forum Excel General
    Replies: 0
    Last Post: 04-21-2006, 01:40 PM
  7. How can I get data from Yahoo Finance?
    By viorelmusca in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 04-11-2005, 07:35 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