我需要为大块的html写一个正则表达式。
<td width=342 align=left style='width:256pt'> HF Acciones Lideres - Clase G</td><td width=24 align=center style='width:18pt'>ARS </td><td width=24 align=center style='width:18pt'>Arg </td><td width=24 align=center style='width:18pt'>Lar </td><td width=60 align=center style='width:45pt'>08/10/14</td><td width=88 align=right style='width:64pt'>1738.383</td><td width=83 align=right style='width:62pt'>51,427,906</td><td width=83 align=right style='width:62pt'>89,401,382</td>
仅在第一个td为HF Acciones Lideres时,我才需要获取日期(08/10/14)和值(1738.383)。我已经编写了这段代码,但是在第一个td不是HF Acciones Lideres的情况下,它会重复一些值-ClaseG。
请参阅(注意:regexr不允许保存完整的html,所以我将放在这里):
http://regexr.com/3alo4
完整的html
http://fondosargentina.org.ar/scripts/cf_EstadisticaDiariaAntDetalle.asp?Fecha=08/10/14&Clasi_Id=00001
最佳答案
您可以使用jQuery搜索方法找到这些值:
$(document).ready(function() {
var $tr = $("td:contains('Lideres - Clase G')").parent();
var date = "";
var total = "";
$tr.children("td").each(function(i) {
if (i==4) date = $(this).text();
if (i==5) total = $(this).text();
});
alert("date="+ date + ", total=" +total);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border=1 cellpadding=0 cellspacing=0 width=728 style="font-family: Arial; font-size: 8 pt; position: absolute; left: 25; table-layout:fixed; width:546">
<tr height=17>
<td width=342 align=left style='width:256pt'> 1810 Renta Variable Argentina</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>08/10/14</td>
<td width=88 align=right style='width:64pt'>13905.228</td>
<td width=83 align=right style='width:62pt'>2,866,017</td>
<td width=83 align=right style='width:62pt'>39,852,620</td>
</tr>
<tr height=17>
<td width=342 align=left style='width:256pt'> 1822 Raices Valores Negociables</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>08/10/14</td>
<td width=88 align=right style='width:64pt'>139941.375</td>
<td width=83 align=right style='width:62pt'>297,644</td>
<td width=83 align=right style='width:62pt'>41,652,710</td>
</tr>
<tr height=17>
<td width=342 align=left style='width:256pt'> AL Renta Variable - Clase A</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>08/10/14</td>
<td width=88 align=right style='width:64pt'>5047.820</td>
<td width=83 align=right style='width:62pt'>277,968</td>
<td width=83 align=right style='width:62pt'>1,403,133</td>
</tr>
<tr height=17>
<td width=342 align=left style='width:256pt'> AL Renta Variable - Clase B</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>08/10/14</td>
<td width=88 align=right style='width:64pt'>5704.307</td>
<td width=83 align=right style='width:62pt'>3,655,663</td>
<td width=83 align=right style='width:62pt'>20,853,021</td>
</tr>
<tr height=17>
<td width=342 align=left style='width:256pt'> AL Renta Variable II - Clase A</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>03/09/12</td>
<td width=88 align=right style='width:64pt'>1604.331</td>
<td width=83 align=right style='width:62pt'>8,658</td>
<td width=83 align=right style='width:62pt'>13,890</td>
</tr>
<tr height=17>
<td width=342 align=left style='width:256pt'>HF Acciones Lideres - Clase G</td>
<td width=24 align=center style='width:18pt'>ARS </td>
<td width=24 align=center style='width:18pt'>Arg </td>
<td width=24 align=center style='width:18pt'>Lar </td>
<td width=60 align=center style='width:45pt'>08/10/14</td>
<td width=88 align=right style='width:64pt'>1738.383</td>
<td width=83 align=right style='width:62pt'>51,427,906</td>
<td width=83 align=right style='width:62pt'>89,401,382</td>
</tr>
</table>