public static readonly string xpath = "/html/body/div[6]/div[2]/div[1]/ul[1]/li", url = "www.zerodm.cn"; string html = HAPCommon.GetHtmlContentByURL(string.Format("http://{0}/", url)); HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument(); htmldoc.LoadHtml(html);
HtmlNodeCollection nodes = htmldoc.DocumentNode.SelectNodes(xpath); //HtmlAgilityPack.HtmlNode xhtml = new HtmlAgilityPack.HtmlNode(HtmlAgilityPack.HtmlNodeType.Element,htmldoc, 0); return nodes;
Nodes is null
xpath 是用 Firebug 找到的路径
你是不是想取到
<em>0</em><span> <font color="red">00-00</font></span><a href="http://t.qq.com/zerodanmei" target="_blank"><font color="purple">ZERO耽美微博,求收听、转播、吐槽!</font></a>
如果是 把 6 改成 5
如果不是, 则 /div[6]/div[2]/div[1]下是没有ul的
是的
我想把UL下的LI全部获取到!
@Mundo Novo: 那你把 6 改成 5
共有 21 个li
@Yu: 非常感谢你。对了。确实是我想要的结果
我太相信firebug 了 /html/body/div[6]/div[2]/div/ul/li/a/font
@Yu: 6改成5就对了。! 太感谢了! 要不今天一天都不知道。
@Mundo Novo: 您能给我大概讲解一些为什么是5么, 我数节点的时候他确实是第6个DIV
@Yu: 如果下标从0开始 5那是对了 可是下标应该是1开始啊
@Mundo Novo:
下标从1开始是没错的
但你要看实际的 html source
第一层共才 6个 div
@Yu: 果然还得还继续校验一遍才行!