+ Reply to Thread
Results 1 to 4 of 4

Get Data from Website (and probably Isolate Value)

Hybrid View

KomicJ Get Data from Website (and... 08-28-2015, 09:16 AM
rkey Re: Get Data from Website... 08-28-2015, 10:13 AM
thelongpants Re: Get Data from Website... 08-28-2015, 10:35 AM
KomicJ Re: Get Data from Website... 08-28-2015, 01:01 PM
  1. #1
    Forum Contributor
    Join Date
    08-28-2015
    Location
    Montreal, Canada
    MS-Off Ver
    2013 on PC, 2011 on MAC
    Posts
    159

    Question Get Data from Website (and probably Isolate Value)

    Hey guys,

    First time I've ever posted here, so please be gentle.

    I'm trying to get data from a website, more specifically Investing.com. I tried to do so using the webquery tool, but it only allows me to import the whole page, not the sections I need. Which makes it a terribly long process, considering I would have to load at the very least 36 different pages, just to get those 4-6 valuable infos. So my guess is VBA/Macro would probably be the better option, but I'm not even sure it'll do.

    Link: http://www.investing.com/etfs/horizo...l?period=86400

    What I'm trying to do basically is to get the "Summary" part of the page, where it shows the Moving Averages, and Technical Indicators, and isolate six values so that I can use them after, in my report sheet. I need the two quotes (ie. Strong Sell, Sell, Buy, etc.) and the four indicators, but only the numbers.

    Now I know how to do a bunch of little 'commun' things with Excel, but I've only been playing with VBA/Macros for a week. I've been able to do a bunch of cool little things so far (force entry in cap letters, and getting stocks info from Yahoo.com, thanks to a very cool tutorial), but this is probably way out of my league. However, I have no problem spending time doing my own research. I just didn't find anything so far, which makes me think that what I'm trying to do may not be possible.

    So if someone here with more knowledge would be kind enough to take a glimpse at the page, and see if it can be done or if I'm just wasting my time trying, that would be a start. And if you have in mind a few terms that I should look for on the internet to achieve such a task, that would be greatly appreciated.

    Thanks

    KJ.

  2. #2
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Get Data from Website (and probably Isolate Value)

    Hi KJ, and welcome to the forum.

    You can try this script to get you going, the output is almost what you wanted.
    Please keep in mind the macro will be based on a 3rd parties website, so you'll be dependant on their layout...
    See also the URL in the comments, it would help you explain the subject even more.

    Sub test()
        URL = "http://www.investing.com/etfs/horizons-betapro-tsx-60-bull-plus-technical?period=86400"
    ' Create and Send HTTP req
        Set objHttp = CreateObject("Microsoft.XMLHTTP")
        objHttp.Open "GET", URL, False
        objHttp.setRequestHeader "Content-Type", "text/xml"
        objHttp.send
    ' Handle Response
        sHTML = objHttp.ResponseText
    'see http://scriptorium.serve-it.nl/view.php?sid=40 for more info about extracting the info
    'Extract the desired information from the returned HTML code (text)
    'To make things a little easier I usually cut of most of the unwanted code first
    'so sHTML is smaller to work with.
        lTopicstart = InStr(1, sHTML, "<!-- ---------Summary Box----------------- -->", vbTextCompare)
        lTopicend = InStr(1, sHTML, "<!-- Tables -->", vbTextCompare)
        sHTML = Mid(sHTML, lTopicstart, lTopicend - lTopicstart)
    'Now extract all text within the hyperlinks <a href..>..</a>
    'because they represent the topics
        i = 1
        lTopicstart = 1
        lTopicend = 1
        Do While lTopicstart <> 0
            i = i + 1
            lTopicstart = InStr(lTopicend, sHTML, "<span class", vbTextCompare)
            If lTopicstart <> 0 Then
                lTopicstart = InStr(lTopicstart, sHTML, ">", vbTextCompare) + 1
                lTopicend = InStr(lTopicstart, sHTML, "</span>", vbTextCompare)
                sAllPosts = sAllPosts & Chr(13) & Mid(sHTML, lTopicstart, lTopicend - lTopicstart)
            End If
        Loop
    'Clean up
        Set oHttp = Nothing
        Debug.Print sAllPosts
    End Sub
    Cheers,
    Rick

  3. #3
    Registered User
    Join Date
    02-06-2013
    Location
    Ezinge, The Netherlands
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    65

    Re: Get Data from Website (and probably Isolate Value)

    Hi KJ,

    I was trying to arrange something for you as well.
    This seems to work. Although your site is pretty slow.

    First the site is opened, then all a loop starts to loop through rows and columns.

    Sub search_ie()
    
    ActiveSheet.Cells.Clear
    
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.AddressBar = True
    IE.MenuBar = True
    IE.navigate "http://www.investing.com/etfs/horizons-betapro-tsx-60-bull-plus-technical?period=86400" 'dummy website used for confidentiality
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
    
    Set objcollection = IE.document.getElementsByClassName("halfSizeColumn float_lang_base_2")(0).getElementsByTagName("Table")(0).getElementsByTagName("tr") '(1)
    
    Dim i As Integer
    For i = 1 To objcollection.Length - 1
        For j = 0 To objcollection(i).getElementsByTagName("td").Length - 1
            ActiveSheet.Cells(i + 1, j + 1).Value = objcollection(i).getElementsByTagName("td")(j).innerText
        Next j
    Next i
    
    End Sub
    If happy with the answer, press 'Add Reputation'

  4. #4
    Forum Contributor
    Join Date
    08-28-2015
    Location
    Montreal, Canada
    MS-Off Ver
    2013 on PC, 2011 on MAC
    Posts
    159

    Re: Get Data from Website (and probably Isolate Value)

    You guys are awesome !

    Can't test it right now, but I will as sure as I get back home. But just the fact that took the time to help me out...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. website scrapiplping to get data from multiplepages of website
    By mpatil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2015, 05:00 AM
  2. [SOLVED] Isolate data inside [ ] ; and ,
    By elbrujo in forum Excel General
    Replies: 3
    Last Post: 05-13-2015, 09:48 PM
  3. how to isolate data from column?
    By elbrujo in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-15-2015, 07:23 PM
  4. Replies: 15
    Last Post: 11-28-2014, 07:10 AM
  5. Averageif WILDCARD for website.com AND EXCLUDE website.com.xx
    By Gerhard.Angeles in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-14-2014, 09:12 AM
  6. Replies: 0
    Last Post: 07-24-2013, 11:16 PM
  7. Opening website, getting data, closing website
    By beta_leonis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2012, 03:50 AM

Tags for this Thread

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