有这样一个网页:
http://stock.finance.sina.com.cn/hkstock/finance/01398.html
网页里面有四张财务报表:重要财务指标、资产负债表、现金流量表、综合损益表;
每张报表的右边都有一个“报表类型”的选择控件,用于选择报表是年报还是季报等;
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();
//string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
string pattern = @"(?i)
pattern += @"
string tableHtml = string.Empty;
foreach (Match m in Regex.Matches(tempStr, pattern))
{
//循环输出
string type = m.Groups["title"].Value.Trim();
switch (type)
{
case "重要财务指标":
tableHtml = m.Groups["table"].Value;
break;
case "资产负债表":
tableHtml = m.Groups["table"].Value;
break;
case "现金流量表":
tableHtml = m.Groups["table"].Value;
break;
case "综合损益表":
tableHtml = m.Groups["table"].Value;
break;
}
}