【问题标题】:Using HTML Agility Pack in windows phone 7在 windows phone 7 中使用 HTML Agility Pack
【发布时间】:2012-08-07 19:17:55
【问题描述】:

如何使用带有 HtmlAgilitypack 的 Linq 从 body 标签后面获取 p 标签中的文本? 我不确定人们说 htmlagility 不支持 xpath。 我会解析html代码。

【问题讨论】:

    标签: html-agility-pack windows-phone-7.1.1


    【解决方案1】:

    使用 HtmlAgility 的最简单方法 ->

    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    
    doc.LoadHtml(string);   //string contains the html code
    
    var paragraphTags = doc.DocumentNode.SelectNodes("p"); //selects all p tags
    
    for (int i = 0; i < paragraphTags.Count; i++)   //loop through the p tags
    {
        String text = paragraphTags[i].InnerHtml;
        //text has your paragraph content. use it here.
    }
    

    【讨论】:

    • SelectNodes 在 pcl 版本的 agilitypack 中似乎不可用。
    猜你喜欢
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2014-07-13
    • 2014-08-31
    相关资源
    最近更新 更多