+ Reply to Thread
Results 1 to 18 of 18

Pulling Specific Elements from Websites Into Excel

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Pulling Specific Elements from Websites Into Excel

    Hi all, I'm trying to create a macro whereby I am able to pull Specific elements into certain cells In Excel from a Odds Checker site. So far I am able to do this in a very vague sense, as in i can pull data but its just not the data i need. For example, I wish to set a table format whereby I pull a horse name from a race into one cell, with the corresponding cells giving the the diffrent betting odds from the same webpage that are being offered. I do have some experience with VBA through A levels but i am new to Excel so please excuse any poor coding:


    Please Login or Register  to view this content.

    I figured that by performing the loop I would be able to see what order the elements came in so then if i wanted say the 5th aTD value, i could change the
    Range("Horsename1").Value = aTD(1) to Range("Horsename1").Value = aTD(5), & this way show the specific text i want in that particular cell. & then if the element is in the aTR element i could do the same & simply reference that. However, When i do this it just seems to pull all of the values in the aTD rather than trimming it down. Also, when the code is correct I plan on adding many more cell values Into the final peice of the code, the table bill be approximately 5*5. Please Help!! I am also thinking to use the GetElementById rather than the by tagname, but whenever i do this i get run time errors & can never pull the data. Any kind of help would be very usefull!! Thank you :D
    Last edited by Cutter; 09-19-2012 at 11:05 AM. Reason: Added code tags

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

    Re: Pulling Specific Elements from Websites Into Excel

    Why not just pull the whole table and filter out what you don't want?

  3. #3
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Pulling Specific Elements from Websites Into Excel

    @ Tvoegt

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

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

    Re: Pulling Specific Elements from Websites Into Excel

    Thanks Cutter

    Here's a function that will pull back the first five odds offered for a given race at a given time for a given horse, it can be used in VBA or as an array formula (over 5 cells)
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Because I wish for this application to be more dynamic, so by just clicking the button it will pull all the relevant data from the site that i want into the correct cells. & when you pull the table it sets it out in excel in a very strange manner that takes a long time to ramble through

  6. #6
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Thanks for the new code @ Kyle123, i will test it out now!

    Also, how would i be able to carry this function out by clicking a button & sign the certain cells to the Elements I'am pulling?
    Last edited by Tvoegt; 09-19-2012 at 02:12 PM.

  7. #7
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Do you know how at all i can just pull specific elements, say horsename with 3 betting agents & the corresponding odds, into specific cells that i have set a value for?? Thanks

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

    Re: Pulling Specific Elements from Websites Into Excel

    I'm not really sure what you are wanting to do, I think it would be much easier if you uploaded a mocked up workbook, with the layout as you want it then tell us what you want where

  9. #9
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Real.xlsm


    The attached File is above. What my Aim to do is to pull the name of the bookmakers Under the Cells "Bookmaker", the same with the horse names, & then have the correct odds in the corresponding boxes with the click of the button, like a table. My main aim is to eventually to be able to pull many more horse & bookmaker odds, but this is a starting block! The only thing i should have to change in the code is the URL so it pulls the data from different horse races, this way it keeps everything dynamic & easy to use

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

    Re: Pulling Specific Elements from Websites Into Excel

    Ok, how's this:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    You Sir, are amazing.

    Could you talk me through the code at all??

    Also, if i were to make it so I could fir the 1st 2 horses into the table, how would I go about doing this??

    Thank you so much!!

  12. #12
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Just One thing, when i have tried to use the code today, for some reason it is no longer working. Is this because there is something i have to change in the code that needs to be updated day by day?? Such as the object or file name. It was working fine when using different URLS to pull data from different races, but as soon as I try to pull races today(diffrent date) It runs through the code fine with no errors, just nothing happens. Because i would have thought that the table & elements would remain in the same place as you have written. Thanks for the help
    Last edited by Tvoegt; 09-20-2012 at 07:56 PM.

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

    Re: Pulling Specific Elements from Websites Into Excel

    Have you tried actually going to the web address manually. It seems that after the race is over, the page is removed

  14. #14
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    I was trying it with a diffrent web address very early this morning but it wouldnt work, however now it seems to work fine which is strange, do you know why this could be?

    But, if the number of horse's in the race is only 4 lets say (less than 8/9) I get an error saying *Object vairiable or With block vairiable not set * on this line of code:

    Please Login or Register  to view this content.
    Is it possible to make it more adaptive so it will pull all the Y'axis for the horses?

    *Because once you can do that, you should be able to pull all data from any sport as number the betting companies remains the same throughout all the web address's
    Last edited by Tvoegt; 09-21-2012 at 06:10 AM.

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

    Re: Pulling Specific Elements from Websites Into Excel

    Ok, slightly different tack:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Thanks alot, how does this code vary??

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

    Re: Pulling Specific Elements from Websites Into Excel

    Mainly it's how we select the table. Before we were selecting the 4th table on the page:
    Please Login or Register  to view this content.
    Now, we are selecting the second element in the oddsTableContainer Div - which should always be the table.
    Please Login or Register  to view this content.
    No data was being returned since the wrong table was being selected for certain pages.

    I've also updated the loop to start further up that table since it was missing the first few horses - it is a very complex table to navigate properly so we have to be a bit nifty in parsing it

  18. #18
    Registered User
    Join Date
    09-19-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Pulling Specific Elements from Websites Into Excel

    Hi Kyle, sorry to re-kindle an old flame; but ive just noticed that when i pull the data into the excel it gives me a maximum of 10 horses, it always starts with the first horse on the list, but it skips a few at the end. How can I make it so It will give me the full range of horses in the race??

    Thanks Alot

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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