【发布时间】:2019-08-10 04:52:02
【问题描述】:
我正在尝试通过使用 x-path 树元素但显示为 null 来获取元素,并且这种类型的 x-path 对我来说适用于其他站点,只有 2% 的站点这种类型的 X-Path 不起作用,我也尝试过来自 chrome 的 x-path 也是,但是当我的 x-path 不起作用时,chrome x-path 也不起作用。
public static void Main()
{
string url = "http://www.ndrf.gov.in/tender";
HtmlWeb web = new HtmlWeb();
var htmlDoc = web.Load(url);
var nodetest1 = htmlDoc.DocumentNode.SelectSingleNode("/html[1]/body[1]/section[2]/div[1]/div[1]/div[1]/div[1]/div[2]/table[1]"); // i want this type // not wroking
//var nodetest2 = htmlDoc.DocumentNode.SelectSingleNode("//*[@id=\"content\"]/div/div[1]/div[2]/table"); // from Google chrome // not wroking
//var nodetest3 = htmlDoc.DocumentNode.SelectSingleNode("//*[@id=\"content\"]"); // by ID but i don't want this type // wroking
Console.WriteLine(nodetest1.InnerText); //fail
//Console.WriteLine(nodetest2.InnerText); //fail
//Console.WriteLine(nodetest3.InnerText); //proper but I don't want this type
}
【问题讨论】:
-
不清楚你在追求什么。您打算写出整张表还是一行?还是别的什么?
-
我还建议使用anglesharp 代替敏捷包。敏捷包似乎不再维护了。
-
QHarr 感谢您的回复...我想要整张桌子
标签: c# .net html-agility-pack