我现在有这么一段HTML代码:
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="700" border="0" cellspacing="2" bgcolor="#FFFFFF">
<tr>
<td class="ourfont1" width="12%" bgcolor="#FFFFFF" align="center"><a href="car-detail-112044.html" target="_blank" title="点击查看详细信息">
<img src="../upload/s_20071213202437.jpg" height=40 width=60 border="0">
</a><br>
<font color=#999999>2000年6月</font></td>
<td class="ourfont1" width="32%" bgcolor="#FFFFFF" height="50"><a href="car-detail-112044.html" target="_blank" title="点击查看详细信息" class="mylink"><font color=blue>2000年福建牌照桑塔纳2000时代超人</font></a>
<br>
<font color="#999999">现有一辆福建莆田牌照的桑塔纳2000时代</font></td>
<td class="ourfont1" width="11%" bgcolor="#FFFFFF" height="50">
<font color="#CC0000">
¥48000
</font></td>
<td class="ourfont1" width="8%" bgcolor="#FFFFFF" height="50">白色</td>
<td class="ourfont1" width="10%" bgcolor="#FFFFFF"> 200000
km</td>
<td class="ourfont1" width="13%" align="center" bgcolor="#FFFFFF">上海
</td>
<td class="ourfont1" width="14%" align="center" bgcolor="#FFFFFF">2008-2-22
</td>
</tr>
</table>
</td>
</tr>
</table>
现在需要从中提取出以下内容:
car-detail-112044.html
s_20071213202437.jpg
2000年福建牌照桑塔纳2000时代超人
¥48000
白色
200000 km
上海
2008-2-22然后将这些内容存入数据库。这样的正则表达式该如何写?请各位高手指点一二,非常感谢!:)
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="700" border="0" cellspacing="2" bgcolor="#FFFFFF">
<tr>
<td class="ourfont1" width="12%" bgcolor="#FFFFFF" align="center"><a href="car-detail-112044.html" target="_blank" title="点击查看详细信息">
<img src="../upload/s_20071213202437.jpg" height=40 width=60 border="0">
</a><br>
<font color=#999999>2000年6月</font></td>
<td class="ourfont1" width="32%" bgcolor="#FFFFFF" height="50"><a href="car-detail-112044.html" target="_blank" title="点击查看详细信息" class="mylink"><font color=blue>2000年福建牌照桑塔纳2000时代超人</font></a>
<br>
<font color="#999999">现有一辆福建莆田牌照的桑塔纳2000时代</font></td>
<td class="ourfont1" width="11%" bgcolor="#FFFFFF" height="50">
<font color="#CC0000">
¥48000
</font></td>
<td class="ourfont1" width="8%" bgcolor="#FFFFFF" height="50">白色</td>
<td class="ourfont1" width="10%" bgcolor="#FFFFFF"> 200000
km</td>
<td class="ourfont1" width="13%" align="center" bgcolor="#FFFFFF">上海
</td>
<td class="ourfont1" width="14%" align="center" bgcolor="#FFFFFF">2008-2-22
</td>
</tr>
</table>
</td>
</tr>
</table>
现在需要从中提取出以下内容:
car-detail-112044.html
s_20071213202437.jpg
2000年福建牌照桑塔纳2000时代超人
¥48000
白色
200000 km
上海
2008-2-22然后将这些内容存入数据库。这样的正则表达式该如何写?请各位高手指点一二,非常感谢!:)
解决方案 »
- 这是该用下拉框的什么事件实现啊
- 在线等,解决了就贴。EXTJS怎么设置窗体上控件的位置呢?
- 想实现一个简单的功能
- js 让页面中所有的form表单为readonly
- 风之石框架研究 之 函数 try catch中的函数我去掉the watch好像没有任何影响啊,ff ie都是如此,这个watch究竟有什么存在
- jquery datatables search 扩展
- selectIndex为啥取不到!!!!很急的几个关于Javascript开发页面的问题,在线等待!!!!
- 如何只显示页面而不执行其中包含的script?
- 大家觉得csdn改版后是变好了还是变差了?
- Ext 缺少对象(ext-all-bug 老是报错)
- 请问我想实现一个网页功能
- 一个关于测试服务器的配置问题
上面的HTML代码就是我采集并整理后得到的数据,现在是要把这个表格中的内容,分别保存到数据库的各个字段中去。
'匹配url和图片的,url分组为1,图片路径分组为2(分组索引根据语言而定,vbs的话是0,1,c#的话就是1,2了)
<a\s+href="([^"]+)"[^>]*>\s*<img\s+src="\.\./upload/([^"]+)"[^>]*>\s*</a>
'匹配名称,分组1
<font\s+color=blue>([^>]+)</font>
'money,分组1
<font\s+color="#CC0000">([^>]+)</font>
'颜色,分组1
<td\s+class="ourfont1"\s+width="8%"[^>]*>([^>]+)</td>
'路程??,分组1
<td\s+class="ourfont1"\s+width="10%"[^>]*>([^>]+)</td>
'地方,分组1
<td\s+class="ourfont1"\s+width="13%"[^>]*>([^>]+)</td>
'日期,分组1
<td\s+class="ourfont1"\s+width="14%"[^>]*>([^>]+)</td>
var str=document.body.innerHTML;
var url=/href="(.+?)".+<img.+src="(.+?)"/i.test(str);
alert(RegExp.$1);
alert(RegExp.$2);
var img=/color=blue>(.+?)<\/font>/i.test(str);
alert(RegExp.$1); var price=/<font.+cc0000>(.+?)<\/font>/i.test(str);
alert(RegExp.$1); var col=/<td.+8%[^>]+>(.+?)<\/td>/i.test(str);
alert(RegExp.$1); var col=/<td.+10%[^>]+>(.+?)<\/td>/i.test(str);
alert(RegExp.$1); var col=/<td.+13%[^>]+>(.+?)<\/td>/i.test(str);
alert(RegExp.$1); var col=/<td.+14%[^>]+>(.+?)<\/td>/i.test(str);
alert(RegExp.$1);
</script>