简体   繁体   中英

get all pagination numbers inside div _ puppeteer

I need to extract all numbers inside a div(pagination numbers + links):

<div id="paging">
    <div class="pagingBlock">&nbsp; 
        <a class="pagingBlock">
            <!-- current page -->
            <b>1</b> 
        </a>,&nbsp;
        <a onclick="this.grid.changePage(2);return false;">2</a>
        <a onclick="this.grid.changePage(3);return false;">3</a>
        <a onclick="this.grid.changePage(4);return false;">4</a>
        <a onclick="this.grid.changePage(5);return false;">5</a>
        <a onclick="this.grid.changePage(6);return false;">6</a>
</div>
</div>

this is my code:

let value = await page.evaluate(() =>{
    
    let elements = document.querySelector('.pagingBlock').textContent
    
    
    console.log(elements)
    })

but it gets undefined. how can I traverse inside a div?

Try this:

const numbers = await page.evaluate(() => Array.from(
  document.querySelectorAll('#paging a'),
  a => a.innerText.trim(),
));
console.log(numbers);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM