How to use waitForSelector in Puppeteer to get all <p> tags on a page?

8 Replies, 1399 Views

Hey everyone!

So, I’m trying to figure out how to use waitForSelector Puppeteer get all <p> tags on a page. I’ve got the basics down, but I’m stuck on grabbing *all* the <p> elements after the page loads.

Here’s what I’ve got so far:
```javascript
await page.waitForSelector('p');
const paragraphs = await page.$$('p');
```
But I’m not sure if this is the *best* way to do it. Does waitForSelector Puppeteer get all <p> tags like this, or is there a smarter way?

Also, what if the page is dynamic and <p> tags load later? Will this still work?

Any tips or fixes would be awesome! Thanks in advance, y’all.

Cheers!

Messages In This Thread
How to use waitForSelector in Puppeteer to get all <p> tags on a page? - by - 11-11-2024, 12:31 AM



Users browsing this thread: 1 Guest(s)