|
Retrieve HTML <option> Values
Hello,
I am trying to retrieve some raw html data from a website using VBA so that I can then import the websites that I need into Excel using a Web Query. The partial website addresses that I need are stored as values within <option> tags, see the example below.
Specifically I need to get all of the string values held within "<option value=" so long as the "<optgroup label="United Kingdom"".
Any help is greatly appreciated.
Thank you.
EXAMPLE HTML
<select class="select sui-ico-racecards" id="select-racecard" title="Cards" onchange="location.href=this.options[this.selectedIndex].value">
<optgroup label="United Kingdom">
<option value="/racing/racecards/29-01-2013/lingfield-park/racecard/545568/lingfield-interactive-mares-maiden-open-nh-flat-race">
13:20
<!--Lingfield Park-->
Lingfield Park </option>
<option value="/racing/racecards/29-01-2013/lingfield-park/racecard/545569/follow-lingfield-park-on-facebook-jumpers-bumper-nh-flat-race">
13:50
<!--Lingfield Park-->
Lingfield Park </option>
etc.
etc.
This is the code that I have tried:
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim col As IHTMLElementCollection
Dim sel As HTMLSelectElement
Dim r As Long
URL = "http://www.sportinglife.com/racing/results"
Set IE = New InternetExplorer
With IE
.navigate URL
.Visible = True
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLdoc = .document
End With
Set col = HTMLdoc.getElementsByTagName("option")
Sheet1.Cells.ClearContents
r = 0
For Each sel In col
Sheet1.Range("A1").Offset(r, 0).Value = sel.getattributes("value")
r = r + 1
Next
|