如何在html上获取特定的字符串? [英] How to get specific string on an html?

查看:69
本文介绍了如何在html上获取特定的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在HTML上获取特定字符串,然后在标签上显示。



PS: 我发布的代码只是缩短解释/问题的一个例子。我真正想要的是一个msg文件HTMLBody上的文本/字符串。



我尝试过:



在这个例子中,我想得到SAMPLE字符串,然后将其显示在按钮下的标签上:



I want to get specific string on an HTML then display it on label.

PS: the code that i have posted is only an example to shortened the explanation/question. What i really want to get is a text/string on a msg file HTMLBody.

What I have tried:

in this example i want to get "SAMPLE" string then display it on the label under the button:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        THIS IS A 
        <label>SAMPLE</label>
        TEXT
        <br />
        <button>GET</button>
        <br />
        <label>LABEL</label>
    </div>
    </form>
</body>
</html>

推荐答案

试用HTMLagilityPACK



Try HTMLagilityPACK

HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();

// There are various options, set as needed
htmlDoc.OptionFixNestedTags=true;

// filePath is a path to a file containing the html
htmlDoc.Load(filePath);

// Use:  htmlDoc.LoadHtml(xmlString);  to load from a string (was htmlDoc.LoadXML(xmlString)

// ParseErrors is an ArrayList containing any errors from the Load statement
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() &gt; 0)
{
    // Handle any parse errors as required

}
else
{

    if (htmlDoc.DocumentNode != null)
    {
        HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");

        if (bodyNode != null)
        {
            // Do something with bodyNode
        }
    }
}







使用ASP.NET中的HtmlAgilityPack(HAP)刮取HTML DOM元素 [ ^ ]


这篇关于如何在html上获取特定的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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