2017-09-18 4 views
0
<html> 
<body> 
    <table> 
     <tbody> 
      <tr> 
       <!-- More things here --> 
      </tr> 
      <tr> 
       <td> 
        <table></table> 
        <table> 
         <tbody> 
          <tr> 
           <td></td> 
           <td>I want this</td> 
          </tr> 
         </tbody> 
        </table> 
        <table></table> 
       </td> 
      </tr> 
      <tr> 
       <!-- More things here --> 
      </tr> 
     </tbody> 
    </table> 
</body> 
</html> 

Das ist also die seltsam aussehende HTML-Struktur. Das Element, das ich möchte, ist das Element, das ich im HTML markiert habe.Parsing Tabelle mit Cheerio

Dies ist der Knoten Js Code, den ich verwende, um das HTML zu analysieren. Ich bin nicht sehr vertraut mit jQuery.

const $ = cheerio.load(body); 
    $('table').find('tbody tr:nth-child(1)').each(()=> { 
     $('td').find('table').each(() => { 
      console.log($(this).text()) 
     }) 
    }) 

Antwort

3

Wenn die Struktur Sie ist (Anzahl der Zeilen, etc.) Fixiert zeigen ...

$('table tr:nth-child(2) table:nth-child(2) tr td:nth-child(2)').text() 

Ich hoffe, es hilft