日期:2014-05-18 浏览次数:21721 次
string url = "http://stock.finance.sina.com.cn/hkstock/finance/01398.html"; WebRequest request = WebRequest.Create(url); //请求url WebResponse response = request.GetResponse(); //获取url数据 StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); string tempStr = reader.ReadToEnd();
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/>"); }