我找不出什么问题。我只是创建这个项目来测试HtmlAgilityPack和我所拥有的。HtmlAgilityPack出现问题
using System;
using System.Collections.Generic;
using System.Text;
using HtmlAgilityPack;
namespace parseHabra
{
class Program
{
static void Main(string[] args)
{
HTTP net = new HTTP(); //some http wraper
string result = net.MakeRequest("http://stackoverflow.com/", null);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
//Get all summary blocks
HtmlNodeCollection news = doc.DocumentNode.SelectNodes("//div[@class=\"summary\"]");
foreach (HtmlNode item in news)
{
string title = String.Empty;
//trouble is here for each element item i get the same value
//all the time
title = item.SelectSingleNode("//a[@class=\"question-hyperlink\"]").InnerText.Trim();
Console.WriteLine(title);
}
Console.ReadLine();
}
}
}
它看起来像我使xpath不是我选择的每个节点,而是整个文档。任何建议为什么这样呢? Thx提前。
为什么不使用'HtmlWeb'直接下载HTML? – Oded 2012-01-28 17:43:24
对于这个问题它并不重要 – gingray 2012-01-28 17:47:33