日期:2014-05-17 浏览次数:21291 次
HttpWebRequest hw = (HttpWebRequest)WebRequest.Create("http://www.hkexnews.hk/listedco/listconews/mainindex/SEHK_LISTEDCO_DATETIME_TODAY_C.HTM");
WebResponse wr = hw.GetResponse();
Stream stream = wr.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.GetEncoding("BIG5"));
string html = sr.ReadToEnd();
string pattern = @"(?i)<tr[^>]*?class=(['""])row\d+\1[^>]*?>\s*?<td[^>]*?>((?:(?!</?td>)[\s\S])*?)</td>\s*?\s*?";
pattern += @"<td[^>]*?>([^<>]*?)</td>\s*?\s*?<td[^>]*?>\s*?<nobr>([^>]*?)\s*?</nobr>\s*?</td>\s*?\s*?<td[^>]*?>";
pattern += @"\s*?<div[^>]*?>\s*?([^<>]+)(?:(?!</?div>)[\s\S])*?</div>\s*?<a[^>]*?href=(['""]?)([^'""]*?)\6[^>]*?>([^<]*?)</a>[\s\S]*?[((]([^(())]*?)[))]";
pattern += @"\s*?</td>\s*?</tr>";
var result = Regex.Matches(html, pattern).Cast<Match>().Select(a => new
{
发放时间 = Regex.Replace(a.Groups[2].Value, @"(?i)<[^>]*?>|\s+", string.Empty),
代码 = a.Groups[3].Value,
股份名称 = a.Groups[4].Value,
文件类型 = a.Groups[5].Value,
文件标题 = a.Groups[8].Value,
文件大小 = a.Groups[9].Value,
文件网址=a.Groups[7].Value
});