Get the Value of HTML Attributes Using Puppeteer

You can get attribute value with evaluate method. await page.evaluate(‘document.querySelector(“span.styleNumber”).getAttribute(“data-Color”)’) Second way $$eval method can also be used. Also attributes called as Array from variable const attr = await page.$$eval(“span.styleNumber”, el => el.map(x => x.getAttribute(“data-Color”))); Output will be [“Blue”, “Green”, “Red”] Your solution const styleNumbers = await page.$$(“span.styleNumber”); for( let styleNumber of styleNumbers ) { … Read more

How to get all html data after all scripts and page loading is done? (puppeteer)

If you want full html same as inspect? Here it is: const puppeteer = require(‘puppeteer’); (async function main() { try { const browser = await puppeteer.launch(); const [page] = await browser.pages(); await page.goto(‘https://example.org/’, { waitUntil: ‘networkidle0’ }); const data = await page.evaluate(() => document.querySelector(‘*’).outerHTML); console.log(data); await browser.close(); } catch (err) { console.error(err); } })();

How do you send a POST request in Puppeteer?

Getting the “order” right can be a bit of a challenge. Documentation doesn’t have that many examples… there are some juicy items in the repository in the example folder that you should definitely take a look at. https://github.com/GoogleChrome/puppeteer/tree/main/examples Here is the example; place the following into an async block: // Create browser instance, and give … Read more

Why is puppeteer reporting “UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!”?

The Navigation failed because browser has disconnected error usually means that the node scripts that launched Puppeteer ends without waiting for the Puppeteer actions to be completed. Hence it’s a problem with some waitings as you told. About your script, I made some changes to make it work: First of all you’re not awaiting the … Read more

Inject jQuery into Puppeteer page

I have used page.addScriptTag to inject js files. … await page.addScriptTag({url: ‘https://code.jquery.com/jquery-3.2.1.min.js’}) … page.addScriptTag – documentation Working example using puppeteer: 0.12.0 import { launch } from ‘puppeteer’ (async () => { const browser = await launch({headless: false}); const page = await browser.newPage(); await page.goto(‘https://example.com’, {waitUntil: ‘networkidle’}); await page.addScriptTag({url: ‘https://code.jquery.com/jquery-3.2.1.min.js’}); await page.close(); await browser.close(); })();

Puppeteer unable to run on Heroku

Here is what worked for me. First, I clear all my buildpacks and then I added the puppeteer-heroku-buildpack and the heroku/nodejs one: $ heroku buildpacks:clear $ heroku buildpacks:add –index 1 https://github.com/jontewks/puppeteer-heroku-buildpack $ heroku buildpacks:add –index 1 heroku/nodejs Then, add the following args to the puppeteer launch function: const browser = await puppeteer.launch({ ‘args’ : [ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)