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
 
That works. Thanks!

I have one small issue: The scrape puts a bunch of text in column A, and then when it gets down to where it shows the positions that I need, it starts putting them in column B. In other words, once I see text in column A and B, I know the next 40 rows are what I need.
So it is:

text
text
text
.
.
.
Pos ' in column A Driver 'in column B So I now know I need the next 40 lines BUT they have the number sign, car number and Drivers name all in column B.
1 #3 Austin Dillon
2 #43 Darrell Wallace Jr.


I need the car number from column B. When I was getting it off of Nascar.com, I could just run this code below and when I saw text in column A, and text in column B, I knew I had what I needed in the next 40 rows. How can I pull that number out of the string?
In other words I need the 3 out of #3 Austin Dillon
and I need the 43 out of #43 Darrell Wallace Jr



For i = 1 To lastRow
If Sheets("Worksheet").Cells(i, 1).Value <> "" And Sheets("Worksheet").Cells(i, 3).Value <> "" Then
eRow = Sheets("Results").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Sheets("Results").Cells(eRow, 2).Value = Sheets("Worksheet").Cells(i + 1, 3).Value
End If
Next i
 
Last edited:
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I've amended the code.


It now splits out the Car Number and the name.. leaving the name in the Name column and adding an extra column on the end for the Car Number.


In addition, it copies JUST that section of data to a different worksheet (Currently called JUSTDATA) where none of the extraneous data is there (i.e. 400+ lines of unwanted information)




Here's the link: https://www.dropbox.com/s/rjhyu3zcigiigmu/MyNascarWebscrape.xlsm?dl=0




Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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