c# – 解析HTML字符串

前端之家收集整理的这篇文章主要介绍了c# – 解析HTML字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > What is the best way to parse html in C#? [closed]15个
解决HTML代码方法吗?

即GetElementByTagName(“abc”).GetElementByTagName(“tag”)

我有这个代码块…

private void LoadProfilePage()
{        
    string sURL;
    sURL = "http://www.abcd1234.com/abcd1234";

    WebRequest wrGETURL;
    wrGETURL = WebRequest.Create(sURL);

    //WebProxy myProxy = new WebProxy("myproxy",80);
    //myProxy.BypassProxyOnLocal = true;

    //wrGETURL.Proxy = WebProxy.GetDefaultProxy();

    Stream objStream;
    objStream = wrGETURL.GetResponse().GetResponseStream();

    if (objStream != null)
    {
        StreamReader objReader = new StreamReader(objStream);

        string sLine = objReader.ReadToEnd();

        if (String.IsNullOrEmpty(sLine) == false)
        {
            ....                   
        }
    }
}

解决方法

你可以使用优秀的 HTML Agility Pack.

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don’t HAVE to understand XPATH nor XSLT to use it,don’t worry…). It is a .NET code library that allows you to parse “out of the web” HTML files. The parser is very tolerant with “real world” malformed HTML. The object model is very similar to what proposes System.Xml,but for HTML documents (or streams).

原文链接:https://www.f2er.com/csharp/96491.html

猜你在找的C#相关文章