Import data from multiple pages of a website into a single Excel sheet

V S S Sarma

New Member
Joined
Jul 13, 2012
Messages
11
I am a cricket buff and like to see statistics. But they run to 47 pages running to 9,394 rows in a website. Copy and paste is not a solution. I look forward to your help in either developing an Excel VBA macro or any other way. Please see the first two pages here:

Page 1
http://stats.espncricinfo.com/ci/en...s;type=batting;view=innings;wrappertype=print
Page 2
http://stats.espncricinfo.com/ci/en...s;type=batting;view=innings;wrappertype=print

I will be grateful to receive an immediate response.
 
Page 1 URL is:
HTML:
http://espn.go.com/mlb/stats/batting/_/split/31/count/1/qualified/false
I guessed the "/count/1" part based on the other pages, to give a uniform URL.

Page 2 URL is:
HTML:
http://espn.go.com/mlb/stats/batting/_/split/31/count/41/qualified/false

Page 3 URL is:
HTML:
http://espn.go.com/mlb/stats/batting/_/split/31/count/81/qualified/false

With that, use a For n = 1 to 121 Step 40 loop (or whatever the last page is) with the BabyNames QueryTables code, updating the Connection string URL with the value of 'n' and the Destination cell argument, as needed.

This is what I came up with - it cycles through but no data actually appears:

Sub BatterVsLeftHand()
Dim nextRow As Integer, n As Integer
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
For n = 1 To 441 Step 40
Application.StatusBar = "Processing Page " & n
nextRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;2015 Regular Season MLB Baseball Batting Statistics and League Leaders - Major League Baseball - ESPN & n & /qualified/false", _
Destination:=Range("A" & nextRow))
.Name = "mlb/stats/batting/_/split/31/count/440/qualified/false"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "22"
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ThisWorkbook.Save
Next n
Application.StatusBar = False
End Sub

I must still be missing something.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The concatenation of the Connection string is wrong. Try:
Code:
Connection:="URL;http://espn.go.com/mlb/stats/batting/_/split/31/count/" & n & "/qualified/false"
Please use CODE tags.
 
Upvote 0
The concatenation of the Connection string is wrong. Try:
Code:
Connection:="URL;http://espn.go.com/mlb/stats/batting/_/split/31/count/" & n & "/qualified/false"
Please use CODE tags.

Sorry about not using the Code tag. Anyhow - that was what I originally had...but the same thing happens. I see the macro processing the pages, moving up by 40. But no actual data gets pulled in. I'm just left with a blank spreadsheet.
 
Upvote 0
Would anyone be willing to help me out. I am trying to get a macro to pull the stats from a multi-page stat site.

The stats are stored:
DeepRoute.com - American Football GM Simulation

DeepRoute.com - American Football GM Simulation

DeepRoute.com - American Football GM Simulation

DeepRoute.com - American Football GM Simulation

DeepRoute.com - American Football GM Simulation

DeepRoute.com - American Football GM Simulation

Any help would be really appreciated, I have a vlookup set up to extract the difference in the stats I need from day to day. Now just need a way to get the data rather than copy/paste.

thanks
 
Upvote 0
Hello, I tried to use this comand to import data from multiple pages of a website but it was not possible to me.
I know where is the problema but I can´t solve it (change page=1)
Could anyone help me with this issue?
Thanks!


Sub siiii()
Dim nextRow As Integer, i As Integer
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
For i = 1 To 5 'this is the page range to be captured. At the time there was 4083 total.
Application.StatusBar = "Processing Page " & i
nextRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row + 1
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.dolarsi.com/cotizaciones_anteriores.asp?page=1&zona=1&dia=1&mes=1&anio=2012&dia1=1&mes1=1&anio1=2015" _
, Destination:=Range("$A$39"))

.Name = _
"cotizaciones_anteriores.asp?zona=1&dia=1&mes=1&anio=2012&submit=Buscar&dia1=1&mes1=1&anio1=2015"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "19"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
ThisWorkbook.Save
Next i
Application.StatusBar = False
End Sub
 
Upvote 0
I've tried this on a particular link but no luck. the sites aren't technically in data table format, but if I do it manually it dumps into exel in a recognizable syntax, which is enough for me to work with the data myself once its in excel.

https://abudhabi.dubizzle.com/motors/used-cars/?page=2

the only issue is a couple of errors I get when I run your script

FormatError, among others.

If any of you have some time, do you think you could take a look?

Many thanks
 
Upvote 0
Warship, my earlier reply was intended for your code above.
Thanks

I've tried this on a particular link but no luck. the sites aren't technically in data table format, but if I do it manually it dumps into exel in a recognizable syntax, which is enough for me to work with the data myself once its in excel.

https://abudhabi.dubizzle.com/motors/used-cars/?page=2

the only issue is a couple of errors I get when I run your script

FormatError, among others.

If any of you have some time, do you think you could take a look?

Many thanks
 
Upvote 0
Can any one help me to extract and import the text from multiple page and then paste it in ONE new sheet in one column, with each page after one another
 
Upvote 0
Can any one help me to extract and import the text from multiple page and then paste it in ONE new sheet in one column, with each page after one another
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,159
Members
449,295
Latest member
DSBerry

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