111,096
社区成员




string url = "http://www.aastocks.com/sc/News/AAFN/101/Page1.html";
WebRequest request = WebRequest.Create(url); //请求url
WebResponse response = request.GetResponse(); //获取url数据
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
string tempStr = reader.ReadToEnd();
//string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
string pattern = @"(?i)<span[^>]*?class=(['""]?)n_DateTime\1[^>]*?>([^<>]*?)</span>[^<>]*?<a[^>]*?href=(['""]?)([^'""]*?)\3[^>]*?>([\s\S]*?)</a>";
foreach (Match m in Regex.Matches(tempStr, pattern))
{
//循环输出
string datetime = m.Groups[2].Value;//2012-08-13 07:19
string href = m.Groups[4].Value;// /sc/News/HK6/101/NOW.501325.html
string text = m.Groups[5].Value;// 《公司业绩》中国优通<08232.HK>半年纯利2065万人民币 增长6%
}
string pattern = @"(?i)<span[^>]*?class=(['""]?)n_DateTime\1[^>]*?>([^<>]*?)</span>[^<>]*?<a[^>]*?href=(['""]?)([^'""]*?)\3[^>]*?>([\s\S]*?)</a>";
foreach (Match m in Regex.Matches(tempStr, pattern))
{
//循环输出
string datetime = m.Groups[2].Value;//网址
string href = m.Groups[4].Value;
string text = m.Groups[5].Value;
}