Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
how can I select all anchor tag href URL that is nested inside a tr inside tbody of a table with javascript

codders.

I want to do some tasks with a puppeteer.

I want to log in to a page and get the URL of the first ten articles listed on that page.

but these urls are nested inside a table. I need to grab the first 10 or even twenty URLs of that page.

here is the structure of the website the

Html body tag has a div tag with #body, inside this div are the 3 tables, the second table is the 9th child inside the div with #body.

--there are 3 Html tables on the page, but the URLs I want to scrape are inside the second table

here is what the second table look like

<table>
<tbody>

<tr> <th>Followed Topics</th> </tr>  

<tr>

<td id="top6803855" class="w"> 

<a name="6803855"></a>
<img src="/icons/normal_post.gif"> 
<b> <a href="/politics">Politics</a> </b> 
    " / "
<b><a href="/6803855/nnamdi-kanu-ifeanyi-ubah-wants">The main article which i want to grab the href</a></b>
    &nbsp;
<a onclick="unfollowtopic('anylink.com', '6803855'); return false;" href="anylink.com">

<img src="/static/delete.png"></a>
<br>

<span class="s">
by <b><a href="/username">username</a></b>.
<b>19</b> posts &amp; <b>389</b> views. <b>12:31am</b> 
(<b><a href="/username">username</a></b>)
</span>

</td>

</tr>

</tbody>

</table>

this is what i have used so far and it work without any issue on localhost.

document.querySelector("body > div > table:nth-child(9) > tbody > tr:nth-child(2) > td > b:nth-child(4) > a").href

i repeat the above selector by changing the no in the :nth-child() so as to grab the remaining tr

but its not working well on Heroku, sometime it select the element, sometime it display error

'Cannot read properties of null (reading 'href')'

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe try to go for last child "b" of the span class:

document.querySelector("body > div > table:nth-child(9) > tbody > tr:nth-child(2) > span.s > b:last > a").href

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda