这是我试图提取突出显示的数据的html文档c#Html敏捷包获取div和跨度节点
我在这个网站上阅读了很多,但无法找到有用的解决方案。 我试过使用
nodes = doc.DocumentNode.SelectNodes(table_title + "/tbody/tr/td");
headers = nodes.Elements("span").Select(d => d.InnerText.Trim());
foreach (var this_header in header)
{
string location = this_header.InnerText.Trim();
Console.Writeline(location);
}
这并没有给我正确的信息。我如何找到我正在寻找的特定内容?
为什么不能在类'today_nowcard-location'选择或其他地方使用? – juharr
headers = nodes.Elements(“/ h1 [@class ='today_nowcard-location']”)。Select(d => d.InnerText.Trim());像那样?我得到一个错误的对象引用未设置为对象的实例。 –
你需要用'//'而不是'/'开始你的xpath,因此它会搜索多个深度级别。你也应该可以直接在'doc.DocumentNode'上做,因为在你的例子中没有看到任何表格。 – juharr