Home > OS >  How to retrieve the first child HTML element but exclude all other elements with querySelector
How to retrieve the first child HTML element but exclude all other elements with querySelector

Time:09-15

Currently using document.querySelector with puppeteer to retrieve the video links from a Tiktok account's HTML code and am having issues retrieving exactly what I need

With this code:

const grabURLs = await page.evaluate(() => {
    const pgTag = document.querySelector('.tiktok-1qb12g8-DivThreeColumnContainer.eegew6e2 div div div div div')
    return pgTag.innerHTML;
})

console.log(grabURLs)

I receive not only the href that I need but also all of the child elements below that, how do I limit it so the only innerHTML I receive is the first child?

<><div >
    <div data-e2e="user-post-item" >
        <div style="padding-top: 132.653%;" />
          <div >
             <a href="https://www.tiktok.com/@nottooshabbycakes/video/7063163560238599430">
                <canvas width="75.38461538461539" height="100" ></canvas>
                <div >
                    <div mode="1" >
                        <img mode="1" src="https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/8ba10e1631d14b75b0bad5988c971113?x-expires=1663250400&amp;x-signature=/3yL04w/MNG9AF1TYWI51Sq41jU=" alt="           
  • Related