+ Reply to Thread
Results 1 to 18 of 18

Extracting Real Time Quote from Google Finance

  1. #1
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Extracting Real Time Quote from Google Finance

    I am helping my friend to build a Excel Function to extract real time quote from Google Finance. I used "MSXML2.XMLHTTP" instead of using QuaryTable and would like to use the InStr Function to retrieve the price. Unfortunately, I could not find the real time quote in responseText of "https://www.google.com/finance?q=". So I change the URL to "https://www.google.com/finance/historical?q=", but the responseText was too long that I could not the most update date.

    e.g.
    <td class="rgt">144.60<td class="rgt">143.00<td class="rgt">144.10<td class="rgt rm">1,381,412<tr><td class="lm">Apr 13, 2015<td class="rgt">144.10<td class="rgt">145.00<td class="rgt">143.20<td class="rgt">144.10<td class="rgt rm">1,810,301

    I could only retrieve the data on Apr 13, 2015 instead of Apr 30, 2015. I really appreciate if someone can advise me.

    Here are my codes:

    Function StockQuote(StockTicker)
    Dim strURL As String, strCSV As String
    Dim http As Object

    strURL = "https://www.google.com/finance/historical?q=" & StockTicker

    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", strURL, False
    http.Send
    strCSV = http.responseText

    Debug.Print strCSV

    StockQuote = strCSV

    Set http = Nothing

    End Function

    I would also like to know the difference between "MSXML2.XMLHTTP.3.0","MSXML2.ServerXMLHTTP" and "MSXML2.XMLHTTP".

    Thanks.
    Last edited by cpfrona; 05-05-2015 at 12:30 AM.

  2. #2
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Can anyone help me

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

    Re: Extracting Real Time Quote from Google Finance

    Perhaps?

    http://investexcel.net/google-financ...otes-in-excel/
    http://www.mrexcel.com/forum/excel-q...el-2007-a.html
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Google finance only provides CSV for stocks listed in US , but my friend need to search for Japanese and Korean Stocks. Therefore, I need to scrap its HTML

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

    Re: Extracting Real Time Quote from Google Finance

    You need to include the URL and StockTicker.
    Google has many pages on finance, from many countries, hence the need to be specific. Which value you wish to scrape?

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Extracting Real Time Quote from Google Finance

    If you just want to get the latest stock price based on the stock name, use the code below (adjusted from what you had, just so you can understand more easily - I personally wouldn't put this in a function):
    Set reference to Microsoft HTML object library.
    Please Login or Register  to view this content.
    Please click the * below if this helps
    Please click the * below if this helps

  7. #7
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Quote Originally Posted by JasperD View Post
    If you just want to get the latest stock price based on the stock name, use the code below (adjusted from what you had, just so you can understand more easily - I personally wouldn't put this in a function):
    Set reference to Microsoft HTML object library.
    Please Login or Register  to view this content.
    Please click the * below if this helps
    Thanks for your help. However, I encounter errors for reading this "http As New MSXML2.XMLHTTP, stock As New HTMLDocument"
    How could I solve it?

  8. #8
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Quote Originally Posted by AB33 View Post
    You need to include the URL and StockTicker.
    Google has many pages on finance, from many countries, hence the need to be specific. Which value you wish to scrape?
    "https://www.google.com/finance/historical?q=" is the URL, just need to put the stockticker or number after "q=".
    For example,
    https://www.google.com/finance?q=0005 is the URL of HSBC which listed in HK.
    https://www.google.com/finance?q=005930 is the URL of Samsung Electronics which listed in Korea.

    I wish t scrape the current price of the stock.

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

    Re: Extracting Real Time Quote from Google Finance

    Jasper's code seems to work.
    You need to tick two boxes on the tools-reference before you run the code: Microsoft HTML object library and Microsoft XML, V.5 or what ever the latest version is.
    For e.g if you do a sub,

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Quote Originally Posted by AB33 View Post
    Jasper's code seems to work.
    You need to tick two boxes on the tools-reference before you run the code: Microsoft HTML object library and Microsoft XML, V.5 or what ever the latest version is.
    For e.g if you do a sub,

    Please Login or Register  to view this content.
    I had ticked those boxes (Microsoft HTML object library and Microsoft XML, V.6.0 ), but I still encountered an error with "stock As New HTMLDocument"

  11. #11
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    VBA.jpg
    I selected the above items in the refereneces

  12. #12
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Quote Originally Posted by cpfrona View Post
    Attachment 392827
    I selected the above items in the refereneces
    I have ticked the "Microsoft HTML Object Library" and it works till "stock.body.innerHTML = http.responseText" with error 91.

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

    Re: Extracting Real Time Quote from Google Finance

    I think it is wrong to use early binding as you found out that not many people know where to find objects in the library. For this reason, I avoid using it, but for some unknown reason to me, one of the object is not working. If you want to get the entire price, you need to comment the first line, instead use the second line.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Quote Originally Posted by AB33 View Post
    I think it is wrong to use early binding as you found out that not many people know where to find objects in the library. For this reason, I avoid using it, but for some unknown reason to me, one of the object is not working. If you want to get the entire price, you need to comment the first line, instead use the second line.
    Please Login or Register  to view this content.
    Thanks very much and it works for me now.
    Could you tell me more about the difference between the latest one and the previous one? I am new to XML and they look similar to me.

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

    Re: Extracting Real Time Quote from Google Finance

    It is the same code, but Jasper used early binding, which means you need to connect to the object (Tick the boxes in the library) before you run the code, while late binding does not require you need to tick any box, just run it. However, I still used one of the object as early binding-stock As New HTMLDocument. If I change the stock as object, the code errors. I do not know the reason (Will find out tomorrow). The code uses a mixture of early binding (stock As New HTMLDocument), so you need to tick the box in the library, but you do not need to tick, Microsoft XML, V.5 since I have changed that part of the code in to late binding.

  16. #16
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Thanks for your guidance

  17. #17
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Extracting Real Time Quote from Google Finance

    Usually when early binding like this fails, I still use it but split it over two lines, like:

    Dim stock as htmldocument
    Set stock = new htmldocument

    That usually fixes problems. Anyway, glad to hear you got it to work!

    Please make sure you click add rep to one of AB33's replies. It's the proper way to show gratitude :-)

  18. #18
    Registered User
    Join Date
    09-19-2014
    Location
    HK
    MS-Off Ver
    2010
    Posts
    16

    Re: Extracting Real Time Quote from Google Finance

    Thanks for your kindly remind.
    Really appreciate you guys.

+ 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. Record real time data (stock quote)
    By chaitreya in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2015, 11:31 PM
  2. Realtime Stock quote from Google Finance and charting
    By kaleem1919 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-21-2014, 06:11 AM
  3. Extracting data from yahoo/google finance to excel
    By wallstreetballa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2013, 10:24 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. Real-time quote on excel Java
    By feejo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2007, 09:35 AM

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