首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Regex.Matches 怎么从网页中获取想要的数据

2013-07-08 
Regex.Matches 如何从网页中获取想要的数据网页中有这样一个tabletable style height:100%table-layou

Regex.Matches 如何从网页中获取想要的数据
网页中有这样一个table
<table style=" height:100%;table-layout:fixed;word-break: break-all" class="QUERYGRID" id="datagrid"><tbody><tr></tr></tbody></table>

如何用一下方法获取
string Pattern2 = @"<table id=""datagrid"".*?</table>";
MatchCollection Matches2 = Regex.Matches(strResult, Pattern2); MatchCollection? Regex
[解决办法]
试试
(?i)<table[^>]*?id=(['""]?)datagrid\1[^>]*?>[\s\S]*?</table>
[解决办法]

一个匹配用Regex.Match
多个匹配用Regex.Matches

(?is)<table[^>]*?id=""datagrid""[^>]*?>.*?</table>

string Pattern2 = @"(?is)<table[^>]*?id=""datagrid""[^>]*?>.*?</table>";
Match Matches2 = Regex.Match(strResult, Pattern2);
Console.WriteLine(Matches2.Value);

热点排行