How can I scrape the results from this website into an excel spreadsheet?

Brad24

Board Regular
Joined
May 4, 2015
Messages
81
Hi, the code changed on this website, and my visual basic in excel no longer works.

I need to scrape the results of this page:
https://www.nascar.com/results/race...gy-nascar-cup-series/advance-auto-parts-clash


Every week, nascar will put the results of the previous race online, and I scrape the results to use in an excel application I have that tallies up the points of a small group of us in a pool.

This is the code that used to work. I didn't write it. Someone probably on this forum gave it to me:

Uly = "URL;" & raceName

Sheets("Worksheet").Activate

ActiveWindow.SmallScroll Down:=12

With ActiveSheet.QueryTables.Add(Connection:=Uly, Destination:=Range("$A$1"))

.Name = "duck-commander-500_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=288
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Due to the way the webpage has been structured, I'm not sure you're going to be able to get the data using that methodology.

There is a different way of web-scraping using the MSTML reference and Internet Control reference...

However, before exploring that - what data did you need from that webpage specifically?

I ask because if it's the following:

Excel 2010
ABCDEFGH
78PosDriverCar MakeTotal PtsBonusLapsLaps LedQualifying Speed
791Brad KeselowskiFord0075430
802Joey LoganoFord007510
813Kurt BuschFord007500
824Ryan BlaneyFord007500
835Austin DillonChevrolet007530
846Denny HamlinToyota007580
857Kyle BuschToyota007500
868Erik JonesToyota007500
879Kevin HarvickFord007520
8810Kyle LarsonChevrolet007510
8911Ryan NewmanChevrolet007500
9012Jimmie JohnsonChevrolet007500
9113Chase ElliottChevrolet0075170
9214Martin Truex Jr.Toyota007500
9315Kasey KahneChevrolet007500
9416Ricky Stenhouse Jr.Ford007500
9517Jamie McMurrayChevrolet007500
96
97A. Dillon1
98D. Wallace Jr.2
99D. Hamlin3
100J. Logano4
101C. Buescher5
102P. Menard6
103R. Blaney7
104R. Newman8
105M. McDowell9
106A. Allmendinger10

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet4
..you can get that (and more) at:

https://sports.yahoo.com/nascar/cup/2018/advance-auto-parts-clash/


with the existing code you've got (you'll need to change the URL in the code, of course) - and it will probably appear at different locations in your spreadsheet than before as the HTML page is different... so perhaps try it out on a new workbook to see if it meets your requirements.

BUT.. you CAN get the data!
 
Upvote 0
Hi, I need to get the drivers name and their position. So 40 drivers and their results in the race.

If I can get the results into a spreadsheet every week, I can figure out how to filter out what I need from that. I know that Nascar puts the results of every race up weekly. I will have a look at this yahoo page. Maybe they put it up weekly as well.
 
Last edited:
Upvote 0
Hi, I need to get the drivers name and their position. So 40 drivers and their results in the race.

If I can get the results into a spreadsheet every week, I can figure out how to filter out what I need from that. I know that Nascar puts the results of every race up weekly. I will have a look at this yahoo page. Maybe they put it up weekly as well.

If all you need are the driver's names and their position, the information in the NASCAR website can be brought through as a Google Search!


All you'd need to do is use for the raceName variable in Uly = "URL;" & raceName


Code:
[COLOR=#333333]

 [/COLOR]    raceName = "https://www.google.co.uk/search?q=Advance+Auto+Parts+Clash"



This is returned using that web address:


Excel 2010
ABC
103PosDriverStatus
1041B. KeselowskiRunning
105Ford·#2
1062J. LoganoRunning
107Ford·#22
1083K. BuschRunning
109Ford·#41
1104R. BlaneyRunning
111Ford·#12
1125A. DillonRunning
113Chevrolet·#3
1146D. HamlinRunning
115Toyota·#11
1167K. BuschRunning
117Toyota·#18
1188E. JonesRunning
119Toyota·#20
1209K. HarvickRunning
121Ford·#4
12210K. LarsonRunning
123Chevrolet·#42
12411R. NewmanRunning
125Chevrolet·#31
12612J. JohnsonRunning
127Chevrolet·#48
12813C. ElliottRunning
129Chevrolet·#9
13014M. Truex Jr.Running
131Toyota·#78
13215K. KahneRunning
133Chevrolet·#95
13416R. Stenhouse Jr.Running
135Ford·#17
13617J. McMurrayDNF
137Chevrolet·#1

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet5

Presumably.. if the NASCAR results are weekly.. then the google search returning the information would be weekly???

Hope that helps!?!
 
Upvote 0
That works but...the 36 races are named at the first of the year, so we have all the names, but sometimes, the race names are changed throughout the year, and it would possibly fail the search.
 
Upvote 0
Marty, did that work for you? When I put this in, it fails and goes to my error handler. The .Name isn't correct, but I thought in the past that I didn't need it anyhow.

Uly = "https://sports.yahoo.com/nascar/cup/2018/daytona-500/"
Sheets("Worksheet").Activate
ActiveWindow.SmallScroll Down:=12
With ActiveSheet.QueryTables.Add(Connection:=Uly, Destination:=Range("$A$1"))
.Name = "duck-commander-500_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=288
 
Upvote 0
Forgot to mention: If you change the name of the workbook (or worksheet), you'll need to change the CONSTs in the code to match.

The workbook is currently named: MyNascarWebscrape.xlsm
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top