+ Reply to Thread
Results 1 to 7 of 7

Help downloading specific data from a webpage!

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    21

    Help downloading specific data from a webpage!

    Hi everyone,

    Could somebody help me out with a very small problem that I have. I am simply trying to grab some data from a particular website, a fantasy football website. I don't want to use the functionality in Excel of adding a connection to a webpage, because this downloads everything on the website and I find it not exact and highly unreliable. I simply want to grab the table of data, in the link below. If someone has a code to do this I don't know if it's JavaScript or VBA I would be really grateful. The link is below and this information updates weekly as games are played.

    http://fantasy.premierleague.com/stats/elements/?element_filter=te_4&stat_filter=total_points

    I have attached a picture to give you an idea of what the data looks like.

    I am using excel 2010.


    Thank you so much!
    Attached Images Attached Images

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Help downloading specific data from a webpage!

    Here you go

    Sub GetData()
        Dim x As Long, y As Long
        Dim htm As HTMLDocument
    
        Set htm = CreateObject("htmlFile")
    
        With CreateObject("msxml2.xmlhttp")
            .Open "GET", "http://fantasy.premierleague.com/stats/elements/?element_filter=te_4&stat_filter=total_points", False
            .send
            htm.body.innerhtml = .responsetext
        End With
    
        With htm.getElementsByTagName("table")(0)
            For x = 0 To .Rows.Length - 1
                For y = 0 To .Rows(x).Cells.Length - 1
                    Sheets(2).Cells(x + 1, y + 1).Value = .Rows(x).Cells(y).innertext
                Next y
            Next x
        End With
    
    End Sub

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Help downloading specific data from a webpage!

    Thanks Kyle for the fast response and code! I'll test this out once I get back to my PC shortly.

  4. #4
    Registered User
    Join Date
    09-28-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Help downloading specific data from a webpage!

    I'm guessing I need the microsoft dao 3.6 object library?
    However I am getting a message:
    error in loading dll
    when I am adding the library in the reference.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Help downloading specific data from a webpage!

    No, you don't need DAO library, for that code you'd have needed the Microsoft HTML Object Library, the code below shouldn't need any

    Sub GetData()
        Dim x As Long, y As Long
        Dim htm As Object
     
        Set htm = CreateObject("htmlFile")
     
        With CreateObject("msxml2.xmlhttp")
            .Open "GET", "http://fantasy.premierleague.com/stats/elements/?element_filter=te_4&stat_filter=total_points", False
            .send
            htm.body.innerhtml = .responsetext
        End With
     
        With htm.getElementsByTagName("table")(0)
            For x = 0 To .Rows.Length - 1
                For y = 0 To .Rows(x).Cells.Length - 1
                    Sheets(2).Cells(x + 1, y + 1).Value = .Rows(x).Cells(y).innertext
                Next y
            Next x
        End With
     
    End Sub

  6. #6
    Registered User
    Join Date
    09-28-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Help downloading specific data from a webpage!

    Hi Kyle,
    That is brilliant, that works perfectly! Thanks so much for creating the code and persisting.
    I will be able to pull off so much data with this code and a loop. I can't believe it. Thanks again
    Daniel

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help downloading specific data from a webpage!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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. Extract data from webpage at a specific time
    By Trader1 in forum Excel General
    Replies: 1
    Last Post: 07-15-2014, 09:08 AM
  2. Pulling specific data from webpage using excel macro
    By aserle in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2013, 08:10 PM
  3. Downloading a list of URLs from Webpage (that requires authentication) to pdfs
    By varsakov in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2013, 10:13 AM
  4. import specific data from a webpage into excel with VBA
    By wolfram13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2013, 01:26 PM
  5. [SOLVED] VBA/Macro to query specific data on webpage
    By Firefighter in forum Excel Programming / VBA / Macros
    Replies: 56
    Last Post: 11-14-2012, 02:01 PM
  6. Replies: 3
    Last Post: 07-29-2012, 05:05 PM
  7. Replies: 0
    Last Post: 01-20-2012, 09:51 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