我可以使用HTML敏捷包呢? [英] Can I use Html Agility Pack for this?

查看:187
本文介绍了我可以使用HTML敏捷包呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到他们的网站上的任何教程。我想知道我可以使用HTML敏捷性包,并用它来分析一个字符串?

I could not find any tutorials on their site. I am wondering can I use Html Agility Pack and use it to parse a string?

就像说我有

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

我可以用敏捷包摆脱&LT的; B&GT; 标签?所有我迄今看到的例子已经加载HTML文档一样。

could I use agility pack to get rid of the <b> tags? All the examples I seen so far have been loading like html documents.

推荐答案

如果它是HTML然后肯定的。

If it's html then yes.

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;

这篇关于我可以使用HTML敏捷包呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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