Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 10:37 PM   PM User | #1
nick1975
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
nick1975 is an unknown quantity at this point
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&nbsp;&nbsp;
<!--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&nbsp;&nbsp;
<!--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
nick1975 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 AM.


Advertisement
Log in to turn off these ads.