+ Reply to Thread
Results 1 to 4 of 4

Retrieve HTML <option> Values

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    5

    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.

  2. #2
    Registered User
    Join Date
    01-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Retrieve HTML <option> Values

    This is the code that I have tried so far:

    Sub Macro3()

    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

    End Sub

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Retrieve HTML <option> Values

    Which dropdown, or whatever, is this for?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    01-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Retrieve HTML <option> Values

    Not sure. On the website they just appear as a series of links.

    See: www.sportinglife.com/racing/results

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1