利用正则表达式将html网页数据变成Web Service[5]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 dancefire 的 blog

            dt.columns.add( "baseline", typeof(double) );
            
xmldatadocument xmldoc = new xmldatadocument( ds );

            
regex expr = new regex(
                @
"<tr bgcolor='#\w+' ><td height='20'>(?<currency>.*)</td>\s*" +
                @
"<td height='20'><p align='right'>(?<bankbuytt>\d*.?\d*)(&nbsp)+.?</td>\s*" +
                @
"<td height='20'><p align='right'>(?<buynotes>\d*.?\d*)(&nbsp)+.?</td>\s*" +
                @
"<td height='20'><p align='right'>(?<sell>\d*.?\d*)(&nbsp)+.?</td>\s*" +
                @
"<td height='20'><p align='right'>(?<base>\d*.?\d*)(&nbsp)+.?</td>\s*"
                
, regexoptions.compiled);
            for(
match m = expr.match(webcontent) ; m.success ; m=m.nextmatch() )
            {
                
string key;
                
datarow row = dt.newrow();
                
row["currency"] = m.groups["currency"];
                
key = m.groups["bankbuytt"].tostring();

本文关键:利用正则表达式将html网页数据变成Web Service
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top