2017-09-18 3 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> 

Donc, c'est la structure HTMl à l'aspect bizarre. L'élément que je veux est l'élément que j'ai marqué dans le HTML.Table d'analyse avec Cheerio

Ceci est le code de Jode Js que j'utilise pour analyser le code HTML. Je ne suis pas très familier avec jQuery.

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

Répondre

3

Si la structure que vous présentez est fixe (nombre de lignes, etc.) ...

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

J'espère que cela aide