Kri*_*ndi 4 c# html-agility-pack
我正在使用C#开发一个简单的Web抓取应用程序,这是我的代码,用于加载从服务器接收的HTML代码HtmlDocument.
string html = res.Content.ToString();
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
Run Code Online (Sandbox Code Playgroud)
每当我尝试使用该htmlDoc.DocumentNode.SelectSingleNode方法时,我收到此错误:
"Html节点不包含SelectSingleNode的引用".
我错过了什么吗?
我正在Visual Studio 2015中开发一个通用应用程序.使用Nuget管理器下载并安装了html敏捷包.
通用应用程序不支持XPath.因此,您无法使用SelectSingleNode或SelectNodes方法.但是你可以使用Linq
doc.DocumentNode.Descendants("a")
.Where(a => a.InnerText.Contains("some text"))
.Select(a => a.Attributes["href"].Value);
Run Code Online (Sandbox Code Playgroud)
获得相同的节点
| 归档时间: |
|
| 查看次数: |
933 次 |
| 最近记录: |