加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 我可以使用Html Agility Pack吗?

发布时间:2020-12-15 08:19:52 所属栏目:百科 来源:网络整理
导读:我在他们的网站上找不到任何教程.我想知道我可以使用 Html Agility Pack并使用它来解析字符串吗? 就像我说的那样 string = "bSome code /b 我可以使用敏捷包来摆脱 b标签?到目前为止我看到的所有示例都像html文档一样加载. 解决方法 如果它是HTML,那么是的
我在他们的网站上找不到任何教程.我想知道我可以使用 Html Agility Pack并使用它来解析字符串吗?

就像我说的那样

string = "<b>Some code </b>

我可以使用敏捷包来摆脱< b>标签?到目前为止我看到的所有示例都像html文档一样加载.

解决方法

如果它是HTML,那么是的.
string str = "<b>Some code</b>";
// not sure if needed
string html = string.Format("<html><head></head><body>{0}</body></html>",str);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

// look xpath tutorials for how to select elements
// select 1st <b> element
HtmlNode bNode = doc.DocumentNode.SelectSingleNode("b[1]");
string boldText = bNode.InnerText;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读