如何在< TD>内访问HTML标记的innerText标签 [英] How to access innerText of HTML tag inside a <TD> tag

查看:324
本文介绍了如何在< TD>内访问HTML标记的innerText标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从包含此内容的网页获取一些文字。我想用href =#spec_Brand获得这条信息。

 < td class =table_spec> 
< dl>
< dt class =table_spec_title>
< span>品牌< / span>
< / a>
< span class =table_spec_titletext>品牌< / span>
< / dt>
< dd class =table_spec_definition>
产品的生产者?
< / dd>
< / dl>
< / td>

我正在尝试使用:

  Set TDelementsA = HTMLdoc.getElementsByTagName(TD)
当r < TDelementsA.Length
如果TDelementsA.className =table_spec则
Sheet4.Range(A1)。Offset(r,c).Value = TDelement.innerText
End If

但它给我:
品牌
产品的生产者?



而不是

spec_Brand



有人可以帮我吗?

解决方案

这是你正在尝试的吗? (注意)为了测试,我在Sheet1的Cell A1中存储了上述HTML)。我也使用IE的Late Binding

  Option Explicit 

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

Set ie = CreateObject(InternetExplorer.Application)
ie.Visible = True
ie。导航关于:空白

ie.document.body.innerhtml =表格(Sheet1)。范围(A1)。值

设置链接= ie。 document.getElementsByTagName(a)

对于每个lnk In链接
如果lnk.classname =href_icon href_icon_help table_spec_titleimgThen
Debug.Print lnk.innertext
退出对于
结束如果
下一个
结束小组

SCREENSHOT




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?

解决方案

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

这篇关于如何在&lt; TD&gt;内访问HTML标记的innerText标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆