获取以下网址里面的表格里的公告内容:http://www.hkexnews.hk/listedco/listconews/mainindex/SEHK_LISTEDCO_DATETIME_TODAY_C.HTM要求是通过正则表达式将公告的内容“匹配”出来,以写入数据库中有以下字段的数据表中发放时间 代码 股份名称 文件类型 文件标题 文件网址 看似挺简单的,但一写正则表达式头都大了,而且上面的网页当中,表格嵌套的太多,实在不知道怎么写呀,求高手帮忙
解决方案 »
- winform问题
- datagridview表头逆向转
- 关于用递归算法按[千分位]拆分字符串的问题
- Update问题。
- 怎么将服务器端xml文件下载到客户端,然后把xml文件中的数据解析生成word文件并在客户端直接打开?
- 小菜提问:C#中如何把文本型转换为Decimal 型?
- 送分问题 怎样禁止ie弹出广告窗口
- 各位请帮忙,思归请帮忙
- 现在的出版社真是为赚钱不择手段!垃圾书猛出!买了几本错字连天!我靠!学习C#还不如看msdn!
- 请问wpf中的griddata控件中header属性怎么通过前台双击来修改?还有个就是后台绑定的时候,那个绑定怎么理解,感觉和其他的绑定不一样啊。
- ado.net连接数据库有几种方法?
- 共享软件如何利用服务器进行用户认证?具体应该如何操作?
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[^>]*?>([^<]*?)</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[6].Value,
文件大小 = a.Groups[7].Value
});
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
});