我正在尝试解析我从网站获取的Node中的表。该表看起来像这样。我想忽略标题和parseonly实际的事务主体。
<tbody><tr class="dgHeader" style="font-weight:bold;">
<th scope="col">Reference 1</th><th scope="col">Reference 2</th><th scope="col">Reference 3</th><th scope="col">Reference 4</th><th scope="col">Gross Amount</th><th scope="col">Discounts/Surcharges</th><th scope="col">Net Amount</th><th scope="col">Means of Payment</th><th scope="col">Form of Payment</th><th scope="col">Payment Folio</th><th scope="col">Branch</th><th scope="col">Time</th><th scope="col">Maturity Date</th><th scope="col">Payment date</th> </tr><tr align="left">
<td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblReferencia1">0000000000000000000000000000000X4D649G66</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblReferencia2"></span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblReferencia3"></span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblReferencia4"></span>
</td><td align="right">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblImporteBruto">$40.00</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblDescuentosRecargos">$0.00</span>
</td><td align="right">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblImporteNeto">$40.00</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblMedioPago">Internet</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblFormaPago">Cash</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblFolioPago">45786172008896142466 </span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblSucursal">4578</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblHora">01:48:59 p.m.</span>
</td><td>
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblFechaVencimiento">00/00/0000</span>
</td><td align="left">
<span id="ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblFechaPago">20/06/2016</span>
</td> </tr> </tbody>
我一直在使用Cheerio,但很难获得id标签来从表中获取数据。
答案 0 :(得分:0)
最终解决了这个问题,并允许我很容易地获得参考代码。
$ = cheerio.load(str, {
ignoreWhitespace: true
});
$('tr').each(function(i, tr){
var reference = $('#ctl00_Contentplaceholder1_gvConcentracionPagos_ctl02_lblReferencia1').text())
}