0

I would like to get some text from a web page containing this. I want to have the piece of information with the href="#spec_Brand".

<td class="table_spec">
    <dl>
        <dt class="table_spec_title">
            <a class="href_icon href_icon_help table_spec_titleimg" title="Which manufacturer is producing the product?" href="#spec_Brand">
                <span>Brand</span>
            </a>
            <span class="table_spec_titletext">Brand</span>
        </dt>
        <dd class="table_spec_definition">
            Producer of the product?
        </dd>
    </dl>
</td>

I'm trying to use:

Set TDelementsA = HTMLdoc.getElementsByTagName("TD")
    While r < TDelementsA.Length
      If TDelementsA.className = "table_spec" Then
         Sheet4.Range("A1").Offset(r, c).Value = TDelement.innerText
    End If

but it gives me: Brand Producer of the product?

In stead of

spec_Brand

Can someone help me?

Community
  • 1
  • 1
user1708574
  • 1
  • 1
  • 1
  • 1
  • You swap from `TDelementsA` in the `Set`, `While` and `If` lines to `TDelement` when you actually write to the worksheet. Hopefully just a typo here and not in the actual code – barrowc Sep 30 '12 at 23:19

1 Answers1

1

Is this what you are trying? (Note: I stored the above html in Cell A1 of Sheet1 for testing). Also I am using Late Binding with IE

Option Explicit

Sub Sample()
    Dim ie As Object
    Dim links As Variant, lnk As Variant

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "About: Blank"

    ie.document.body.innerhtml = Sheets("Sheet1").Range("A1").Value

    Set links = ie.document.getElementsByTagName("a")

    For Each lnk In links
        If lnk.classname = "href_icon href_icon_help table_spec_titleimg" Then
            Debug.Print lnk.innertext
            Exit For
        End If
    Next
End Sub

SCREENSHOT

enter image description here

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Thanks, as stated I'm looping through the TD elements. A 2 column table and the left column of the table has the text hidden inside tags and the right column the innerText is what I want. So I was using the TD tag. But I guess I could loop through the table 2 times, for column one searching for -tags and for column two searching for -tags; Although I want to understand if and how I can access, the tags within tags. – user1708574 Sep 30 '12 at 03:29