我现在有这么一段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然后将这些内容存入数据库。这样的正则表达式该如何写?请各位高手指点一二,非常感谢!:)

解决方案 »

  1.   

    错了@@在js中先取到td对象,再去取innerText属性就可以了
      

  2.   

    不是
    上面的HTML代码就是我采集并整理后得到的数据,现在是要把这个表格中的内容,分别保存到数据库的各个字段中去。
      

  3.   

    所有数据格式都是这样的话就好写,如果不规则的话比较难搞可以试试下面的正则
    '匹配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> 
      

  4.   

    <script>
    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>
      

  5.   

    把你的html粘进去看看?<textarea onchange="this.value=this.value.split(/<[^>]*>/).join('')" style="height:500;width:800"/>