2012-03-19 8 views
-1

this pageを参照してください。HTMLファイルの本文タグを読み取る方法

私はHTMLを読むことができますが、<Body>タグを選んでパネルに表示したいと思います。

私はこのコードを書かれている:

WebRequest req = WebRequest.Create("http://www.taxmann.com/taxmannflashes/whatsnew.aspx?sid=9578&stype=1"); 

WebResponse res = req.GetResponse(); 

StreamReader sr = new StreamReader(res.GetResponseStream()); 
string htmlResp = sr.ReadToEnd(); 
String htmlBody = ""; 

if (htmlResp.ToLower().Contains("<div id=\"dvreadmore\">")) 
{ 
    int startIndex = htmlResp.ToLower().IndexOf("<div id=\"dvreadmore\">"); 
    int lastIndex = htmlResp.ToLower().IndexOf("</html>\n</div>"); 
    if (lastIndex == -1) 
    { 
     lastIndex = htmlResp.ToLower().IndexOf("</html></div>"); 
    } 
    htmlBody = htmlResp.Substring(startIndex + 21, lastIndex + 7); 
    String final = htmlBody; 
} 

私は値を取得しています "ナルfinalhtml体null値を。"私は<Body>タグを選んでいます。

私は間違っていますが、どうすれば修正できますか?

答えて

1

私はhtmlagilitypack.codeplex.comを使ってhtmlを読むことをお勧めします。それはまた、ナゲットを介してインストールすることができます。

関連する問題