我正在努力获取在下面代码中的属性值中包含特定字符串的所有HTML标记
<meta name="DCSext.oo_market" content="en-us">
<a href="http://office.microsoft.com/en-us/support/" title="Find help for Word">
<a href="http://windows.microsoft.com/en-us/windows-live/microsoft-account-help#microsoft-account=tab1" title="Microsoft Account">我想要在属性中包含"en-us“的所有标记,这意味着我的输出应该返回所有上述html标记。有人能帮我如何使用HTML敏捷包获得它吗?
发布于 2013-10-30 14:25:11
您可以使用下面的XPath //*[@*[contains(., 'en-us')]]来选择任何具有包含字符串en-us的属性的元素
HtmlDocument doc = new HtmlDocument();
doc.Load(path_to_html_file);
var nodes = doc.DocumentNode.SelectNodes("//*[@*[contains(., 'en-us')]]");或LINQ way:
var nodes = doc.DocumentNode.Descendants()
.Where(n => n.Attributes.Any(a => a.Value.Contains("en-us")));https://stackoverflow.com/questions/19684679
复制相似问题