我有关于'http://stackoverflow.com/'的跟踪xpath'/ html / body / div [4] / div [2] / div / div / h1',即'Top Questions'标题。
如何在HtmlAgilityPack中使用它?
var wc = new WebClient();
wc.Encoding = Encoding.UTF8;
var html = wc.DownloadString("http://stackoverflow.com/");
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
var node = htmlDoc.DocumentNode.SelectNodes("/html/body/div[4]/div[2]/div/div/h1");
返回null
答案 0 :(得分:1)
适合我。 .Dump()就是在LinqPad中使用它。
var url = "http://stackoverflow.com/";
new HtmlWeb().Load(url)
.DocumentNode
.SelectSingleNode("/html/body/div[4]/div[2]/div/div/h1")
.InnerText.Dump();
结果:
Top Questions
有一些间距。