何がうまくいかないのか分かりません。私はちょうどHtmlAgilityPackと私が持っているものをテストするためのpojectを作成します。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。
なぜHTMLを直接ダウンロードするために 'HtmlWeb'を使用していませんか? – Oded
この問題は重要ではありません – gingray