-1
我可以閱讀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體空值。」我想選擇<Body>
標籤。
我在做什麼錯,我該如何解決?