你用HtmlAgilityPack试试,下载地址http://htmlagilitypack.codeplex.com/使用如下 HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.Load(Server.MapPath("~/test.txt")); HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes(@"//tbody//tr"); foreach (HtmlNode node in nodes) { Response.Write(node.SelectSingleNode(@"td[1]/a").Attributes["href"].Value + "<br/>"); Response.Write(node.SelectSingleNode(@"td[1]/a").InnerText + "<br/>"); Response.Write(node.SelectSingleNode(@"td[2]/span").InnerText + "<br/>"); Response.Write(node.SelectSingleNode(@"td[3]").InnerText + "<br/>"); Response.Write(node.SelectSingleNode(@"td[4]/span").InnerText + "<br/>"); }

解决方案 »

  1.   

    非常感谢,但是又出现了一个问题啊,就是这一句之后, HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(@"//table//tr");
     系统老是提示要用new关键字,但是用了new关键字之后,编译又过去不,这是怎么一回事呢?string url = "http://www.aastocks.com/SC/Stock/CompanyFundamental.aspx?CFType=8&symbol=00001";            WebRequest request = WebRequest.Create(url); //请求url
                WebResponse response = request.GetResponse(); //获取url数据            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
                string tempStr = reader.ReadToEnd();            this.richTextBox1.Text = tempStr; //将数据写入到textbox中            StringBuilder str = new StringBuilder();            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
               
                HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(@"//table//tr");
                            str.Append(nodes.Count.ToString());