Copying Data From Website

Sami2i

New Member
Joined
Aug 9, 2012
Messages
6
I am needing to collect data off of a website. It is all in table format already and I have experimented with Data>Get External Data>From Web. This is ideal and works perfectly. However I need to get more information from it.

The URL are

http://example.com/representation/job-asstd?sort=coconst_order&start=
1
http://example.com/representation/job-asstd?sort=coconst_order&start=50
http://example.com/representation/job-asstd?sort=coconst_order&start=100
http://example.com/representation/job-asstd?sort=coconst_order&start=150
http://example.com/representation/job-asstd?sort=coconst_order&start=200
and so on in multiples of 50.

The table is in the same place on every page.

How would I set this up to copy the table from these pages onto the next free row.

Thanks

Sam
 

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
What I usually do, run a loop and create a new sheet for every download.
Then aggregate everything into one sheet at the end, given that the data is in the same place for every sheet, this will be an easy for each.

Example code:

Code:
Sub StartMultipleDownload()
Dim i As Long
Dim ws As Worksheet
i = 1
Do While i <= 201
    Set ws = Worksheets.Add
    Call DownloadWebquery(ws, i)
    i = i + 50
Loop
End Sub

Code:
Sub DownloadWebquery(ws As Worksheet, i As Long)
With ws.QueryTables.Add(Connection:= _
        "URL;http://example.com/representation/job-asstd?sort=coconst_order&start=" & i, Destination:=ws.Range("A1"))
        .Name = "example"
        .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
End Sub
 
Last edited:
Upvote 0
Spurious

I do not really know how to use macro, please can you quickly explain how to implement your code

Thanks

Sam
 
Upvote 0
Spurious

I do not really know how to use macro, please can you quickly explain how to implement your code

Thanks

Sam


Yes, sorry about that.

Do Alt + F11, the VBA Editor opens.
Then go to Insert --> Module.

On the left side, you see an explorer structure with modules.
Double click on the Module1 (should be the name of it).

Then copy and paste the code I posted above into it.

Now hit F5 and run the Macro "StartMultipleDownload".

At the moment the maximum of results are 250, change this portion to account for more:
Code:
Do While i <= [COLOR=#ff0000]201[/COLOR]

After running the code, you have a lot of worksheets with the data.
In order to aggregate them, you need to have another macro doing it.
Since I have no idea how the results look like in the Excel sheet, I cant help you there.

If you only got 250 results, copy and pasting the 5 sheets should do the trick.
You could use the macro recorder doing this, then you will have a macro (albeit badly constructed one) that will automate the process for you.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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