如何在html中查找包含特定文本的标记名称 [英] How to find a tag name in html which contains a specific text

查看:318
本文介绍了如何在html中查找包含特定文本的标记名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


请提供代码以查找包含特定文字的html标记名称或类名称或ID。



例如,


我想找到一个包含文字"copyright"的标签名称。来自打击网站地址


https://www.mrexcel.com/forum/excel-questions/731796-extract-text-into-excel-web-page-html-source- code-2.html?s = 3f64ac775f8ee0c0004edc866e3b5934



谢谢,


pazhani

解决方案

您好


在Excel中使用VBA从网页中提取一个值


使用VBA获取网页中类标记的内容


常见的VBA方法&网络自动化中使用的属性


因此您可以尝试引用该链接并尝试开发自己的代码以满足您的要求。


免责声明:此回复包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 Microsoft不控制这些网站,也未测试在这些网站上找到的任何软件或信息;因此,Microsoft不能就其中发现的任何软件或信息的质量,安全性或适用性做出任何陈述。使用互联网上的任何软件都存在固有的危险,并且Microsoft提醒您在从互联网上检索任何软件之前确保您完全了解风险的


问候


Deepak



问候


迪帕克


Hi,

Kindly give the code for find the html tag name or class name or ID which contains a specific text.

For example,

i want to find a tag name that contains a text "copyright" from blow given website address

https://www.mrexcel.com/forum/excel-questions/731796-extract-text-into-excel-web-page-html-source-code-2.html?s=3f64ac775f8ee0c0004edc866e3b5934

thanks,

pazhani

解决方案

Hi pazhanivel a,

from the description of the thread, I can see that you are working with Website.

so here , you need to set reference to Microsoft Internet Controls and Microsoft HTML Object Library.

then you can use code like below to access the information from Web Page.

Option Explicit

Sub Test()

Dim ie As New InternetExplorer
Dim doc As New HTMLDocument

With ie

    .Visible = True
    .Navigate "https://www.federalreserve.gov/releases/h3/current/"

    'can place code to wait for IE to load here .. I skipped it since its not in direct focus of question

    Set doc = .Document

    Dim t As HTMLTable
    Dim r As HTMLTableRow
    Dim c As HTMLTableCol

    Set t = doc.getElementById("t1tg1")

    'loop through each row
    For Each r In t.Rows

        If r.Cells(0).innerText = "Mar. 2016" Then Debug.Print r.Cells(1).innerText

        'loop through each column in the row
        'For Each c In r.Cells

        '    Debug.Print c.innerText

        'Next

    Next

End With

End Sub

Reference:

Retreiving tag from table on website using VBA and put into excel

Trying to extract ONE value from a webpage with VBA in Excel

Get content of class tag in webpage using VBA

Common VBA Methods & Properties used in web automation

so you can try to refer the link and try to develop your own code to fulfil your requirement.

Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Regards

Deepak

Regards

Deepak


这篇关于如何在html中查找包含特定文本的标记名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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