利用正则表达式将html网页数据变成Web Service[2]
[入库:2005年8月18日] [更新:2007年3月24日]
对其代码分析后,给出了一个正则表达式,当然这个表达式还不完善,但是针对目前比较固定的中行的汇率页面来说,暂时还没有问题。
@"<tr bgcolor='#\w+' ><td height='20'>(?<currency>.*)</td>\s*" +
@"<td height='20'><p align='right'>(?<bankbuytt>\d*.?\d*)( )+.?</td>\s*" +
@"<td height='20'><p align='right'>(?<buynotes>\d*.?\d*)( )+.?</td>\s*" +
@"<td height='20'><p align='right'>(?<sell>\d*.?\d*)( )+.?</td>\s*" +
@"<td height='20'><p align='right'>(?<base>\d*.?\d*)( )+.?</td>\s*"
然后过滤就非常简单了。我一直以为代码是最好的说明,特别是对于优雅的语言来说,因为我就不多说了,代码伺候。
这是所建webservice页面foreignexchange.asmx的代码:
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.diagnostics;
using system.web;
using system.net;
using system.web.services;
using system.xml;
using system.text;
using system.text.regularexpressions;
using system.io;
namespace chinabank
{
/// <summary>
/// summary description for foreignexchange.
/// </summary>
[webservice(namespace="http://dancefires.com/chinabank/")]
public class foreignexchange : system.web.services.webservice
{
public foreignexchange()
{
//codegen: this call is required by the asp.net web services designer
initializecomponent();
}
#region component designer generated code
本文关键:利用正则表达式将html网页数据变成Web Service
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)