2011-12-06 35 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

:明白了man.thanks – Kaka