'How to click on a link with page.link but without id (it has class)
This is my code by now
async function main(){
for(int=0;int<50;int++){
const allLinks = await getLinks();
//console.log(allLinks);
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
const scrapedData = [];
for(let link of allLinks){
const data = await getPageData(link,page);
// const secondToWait = (Math.floor(Math.random()*5) + 1)*100; //número aleatorio entre 1000 y 4000 (entre 1 y 4 segundos)
// await page.waitForTimeout(3000) //van a quitar 'waitfor', pero 'waitForTimeout' es parecido; waits 3 seconds before it goes to the next page (a veces que cargen tan rápido las páginas puede causar problemas)
scrapedData.push(data);
}
await page.click('#next a');
}
the '#next' is the class, but it doesent work 'cause i need the id. Any ways to solve that? I traed to find, but i only find answares for bottoms, and dosent work in my case.
This is the code from the page im scraping
<div>
<ul class="pager">
<li class="current">
Page 1 of 50
</li>
<li class="next"><a href="catalogue/page-2.html">next</a></li>
</ul>
</div>
</div>
</section>
(the page: https://books.toscrape.com/)
Solution 1:[1]
# is for ID, for class use dot . so it
await page.click('.next a');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | uingtea |
