2
我试图做的是我有一段下面列出的html代码。我需要锚标记中的内容。HtmlAgilityPack:获取字符串内的锚标记内容的问题
HtmlDocument newHtml = new HtmlDocument();
newHtml.OptionOutputAsXml = true;
var content = "<div class="business-name-container">
<span class="tier_info"></span>
<h3 class="title fn org">
<a href="http://www.abc.com/nationwide/mip/xyz?lid=161004592" class="url link">Foo</a>
</h3>
</div>";
newHtml.Load(content);
HtmlNode doc = newHtml.DocumentNode;
var findContent = doc.SelectNodes("//a[@class='url link']");
foreach (var aContent in findContent)
{
if (acontent.InnerHtml != null)
{
Console.WriteLine("Content: " + acontent.InnerHtml);
}
}
但我没有得到结果。 我想输出是 “内容:富”
现在我在newHtml.Load(content)行中出现错误“路径中的非法字符”; 是必要将字符串转换为HtmlDocument?我们不能直接从字符串中获取数据吗? – pkdq
你正在使用的HTML敏捷包,因此,这就是我的答案使用.. –
抱歉扎克米没有得到错误的地方。实际上,在C#中新增了一个,而在我现在要去哪里的项目中,我感到困惑。仍然感谢你的时间和帮助。非常感谢扎克。 – pkdq