2011-12-06 11 views
0
using System; 
using BankNew; 
using HtmlAgilityPack; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     try 
     { 
      //source.Deposite(float.Parse(txtBox1.Text)); 
      //source.TransferFunds(destnation, float.Parse(tbWithdraw.Text)); 
      //lblBalance.Text = source.Balance.ToString(); 

      HtmlDocument htmlDoc = new HtmlDocument(); 
      string filePath = "http://localhost:50846/Website/TestSourceCode.txt"; 
      // There are various options, set as needed 

      // filePath is a path to a file containing the html 
      htmlDoc.LoadHtml(filePath); 


      if (htmlDoc.DocumentNode != null) 
      { 
       // HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("/body"); 
       HtmlNodeCollection links=htmlDoc.DocumentNode.SelectNodes("//a"); 

       foreach (HtmlNode node in links) 
       { 
        string title = node.InnerText; 
        // txtBox1.Text = title; 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      Response.Write(ex.Message); 
      Response.End(); 
     } 

    } 
} 
+1

テキストファイルをロードしていて、HTMLパーサーがノードを見つけると思われますか?ファイルはどのように見えますか? – Oded

+0

@oded:申し訳ありませんが、私は別のファイル(テキストとHTML)を試していました。 – Kaka

答えて

0

は、あなたの修正を明確にするために.....今

HtmlWeb web = new HtmlWeb(); 

HtmlDocument htmlDoc = web.Load("http://localhost/Website/TestSourceCode.htm"); 
0

作業、LoadHtmlは、実際のHTMLコンテンツの文字列を期待しています。 Loadは、あなたが意図したURLからHTMLコンテンツを読み込みます。

+0

:それは男だった。 – Kaka

関連する問題