VBA to scrap data from URL

lugui

New Member
Joined
Nov 23, 2018
Messages
1
In the course of learning to scrap data from URL, I have been using Web Query function. However, when I try to get stock option data from this site https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/dqe181123.htm , I end up only getting the header and not the content.

In particular , I would like to get the stock option data for "TCH" using VBA.

Any help would be appreciated


Regards

lugui
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the Board

Code:
Sub Scrapper()
Dim IE As Object, ws As Worksheet, r As Range, rend As Range, cp$
cp = "TCH"                              ' desired company
Set ws = Sheets("Sheet5")               ' where page data will go
With ws
    .Cells.ClearContents
    .Activate
    [a1].Activate
End With
Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Visible = True
    .navigate "https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/dqe181123.htm"
    Do Until .readyState = 4: DoEvents: Loop
End With
IE.ExecWB 17, 0                         ' select all
IE.ExecWB 12, 2                         ' copy
ws.PasteSpecial "Texto", False, False   ' for English version use Text instead
Set r = ws.Cells.Find("class " & cp, ws.[a1], xlValues, xlPart, xlByRows, xlNext, False)    ' data starts here
Set rend = ws.Cells.Find("total put", r, xlValues, xlPart, xlByRows, xlNext, False)         ' data ends here
Sheets("summary").Cells.ClearContents
ws.Range(r, rend).Copy Sheets("summary").[a1]                                               ' copy desired data
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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