事情是这样的,现在跟着老师做一个机器人软件开发。是用来参加比赛用的。
可能可以说是人工智能吧。反正老师让我做一个天气预报的程序。
程序我打算是这样做的:因为要机器人把天气信息读出来,所以我做的程序是先连接到一个天气预报的网站,,然后打算查找自己所需要的天气信息。oh,对,开发环境是是VC6.用MFC开发。
找到一个网站以后,应该可以提取网页里面的源码吧,然后我想用正则表达式来查找我所需要的信息。
VC6没有正则表达式,所以要配置boost库才能用正则表达式,然后现在要请教各位大侠正则表达式怎样写。
先看看小弟的程序界面:
下面的天气提示是用webbrowser控件来完成的。
然后下面的是webbrowser里面的网页源码:
Code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="http://weather.qq.com/7v/css/wz1.css" type="text/css">
<script type="text/javascript" src="http://weather.news.qq.com/js/px.js"></script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0"><div id="ArtList">
<table width="606px" border="0" cellpadding="0" cellspacing="0" background="http://mat1.qq.com/weather/images/pub/t_bg.gif" align="center"><tr>
<td width="6%" height="38" align="center"><img src="http://mat1.qq.com/weather/images/pub/arr_3.gif" width="11" height="10"></td>
<td width="64%" align="left" class="px14 tred"><strong>2009年09月04日
北京</strong></td>
<td width="30%" align="left" class="px14 tred">气象信息由<a href="http://www.tq121.com.cn/" target="_blank">中央气象台</a>提供</td>
</tr></table>
<table width="560" height="110" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3DFEE" class="mt6">
<tr><td height="27" colspan="3" align="left" background="http://mat1.qq.com/weather/images/pub/p_titbg.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<td width="3%"> </td>
<td width="68%" class="blues"><strong>当前天气</strong></td>
<td width="29%" align="center" class="blues"></td>
</tr></table></td></tr>
<tr>
<td width="208" height="80" align="center" bgcolor="#FFFFFF"><img width="64" height="64" src="http://mat1.qq.com/weather/images/big/showerday.gif"></td>
<td width="165" align="center" bgcolor="#EDF2F8" class="blues">阵雨<br>18℃~26℃
</td>
<td width="183" align="left" bgcolor="#FFFFFF" class="explain blues">·风力:微风<br>
·紫外线强度:弱<br>
·空气质量:良
<!--[if !IE]>|xGv00|766654629597a809a7af4415e434fe37<![endif]-->
</td>
</tr>
</table>
<table width="560" height="110" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3DFEE" class="mt6">
<tr><td height="27" align="left" background="http://mat1.qq.com/weather/images/pub/p_titbg.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<td width="3%"></td>
<td class="blues"><strong>72小时天气预报</strong></td>
</tr></table></td></tr>
<tr><td align="center" bgcolor="#FFFFFF"><table width="558" height="156" border="0" cellpadding="0" cellspacing="0"><tr>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-04</td></tr>
<tr><td height="60" align="center"><img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/showerday.gif"></td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">阵雨<br>18℃~26℃
<br>微风</td></tr>
</table></td>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-05</td></tr>
<tr><td height="60" align="center">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/showerday.gif">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/smallrain.gif">
</td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">阵雨转小雨<br>18℃~25℃
<br>微风</td></tr>
</table></td>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-06</td></tr>
<tr><td height="60" align="center">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/midrain.gif">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/smallrain.gif">
</td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">中雨转小雨<br>15℃~19℃
<br>微风</td></tr>
</table></td>
</tr></table></td></tr>
</table>
</div></body>
</html>
<!--[if !IE]>|xGv00|eb0a969cd2b5716a2a834ace374d79f8<![endif]-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="http://weather.qq.com/7v/css/wz1.css" type="text/css">
<script type="text/javascript" src="http://weather.news.qq.com/js/px.js"></script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0"><div id="ArtList">
<table width="606px" border="0" cellpadding="0" cellspacing="0" background="http://mat1.qq.com/weather/images/pub/t_bg.gif" align="center"><tr>
<td width="6%" height="38" align="center"><img src="http://mat1.qq.com/weather/images/pub/arr_3.gif" width="11" height="10"></td>
<td width="64%" align="left" class="px14 tred"><strong>2009年09月04日
北京</strong></td>
<td width="30%" align="left" class="px14 tred">气象信息由<a href="http://www.tq121.com.cn/" target="_blank">中央气象台</a>提供</td>
</tr></table>
<table width="560" height="110" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3DFEE" class="mt6">
<tr><td height="27" colspan="3" align="left" background="http://mat1.qq.com/weather/images/pub/p_titbg.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<td width="3%"> </td>
<td width="68%" class="blues"><strong>当前天气</strong></td>
<td width="29%" align="center" class="blues"></td>
</tr></table></td></tr>
<tr>
<td width="208" height="80" align="center" bgcolor="#FFFFFF"><img width="64" height="64" src="http://mat1.qq.com/weather/images/big/showerday.gif"></td>
<td width="165" align="center" bgcolor="#EDF2F8" class="blues">阵雨<br>18℃~26℃
</td>
<td width="183" align="left" bgcolor="#FFFFFF" class="explain blues">·风力:微风<br>
·紫外线强度:弱<br>
·空气质量:良
<!--[if !IE]>|xGv00|766654629597a809a7af4415e434fe37<![endif]-->
</td>
</tr>
</table>
<table width="560" height="110" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3DFEE" class="mt6">
<tr><td height="27" align="left" background="http://mat1.qq.com/weather/images/pub/p_titbg.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<td width="3%"></td>
<td class="blues"><strong>72小时天气预报</strong></td>
</tr></table></td></tr>
<tr><td align="center" bgcolor="#FFFFFF"><table width="558" height="156" border="0" cellpadding="0" cellspacing="0"><tr>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-04</td></tr>
<tr><td height="60" align="center"><img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/showerday.gif"></td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">阵雨<br>18℃~26℃
<br>微风</td></tr>
</table></td>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-05</td></tr>
<tr><td height="60" align="center">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/showerday.gif">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/smallrain.gif">
</td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">阵雨转小雨<br>18℃~25℃
<br>微风</td></tr>
</table></td>
<td width="186"><table width="175" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="23" align="center" bgcolor="#EEEEEE">2009-09-06</td></tr>
<tr><td height="60" align="center">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/midrain.gif">
<img width="44" height="44" src="http://mat1.qq.com/weather/images/sml/smallrain.gif">
</td></tr>
<tr><td height="57" align="center" bgcolor="#EEF3F8">中雨转小雨<br>15℃~19℃
<br>微风</td></tr>
</table></td>
</tr></table></td></tr>
</table>
</div></body>
</html>
<!--[if !IE]>|xGv00|eb0a969cd2b5716a2a834ace374d79f8<![endif]-->
我需要的信息是:
以上图为例:
时间(2009年9月04日)
地点(北京)
当前天气(阵雨 18°C~26°C 风力:微风 紫外线强度:弱 空气质量:良)
暂时需要的信息就这么多,因为我需要把这些信息告诉机器人让机器人读出来,所以就搞得有点麻烦了)
而且只能用VC6开发。。。
希望各位帮忙写写那些正则表达式。
如果有更好的建议大家也可以指点一下。
写写