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>
<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 & <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')'
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