Im getting the error Error: net::ERR_TIMED_OUT at http://lumtest.com/myip.json
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--proxy-server=191.243.218.249:53281']
});
const page = await browser.newPage();
await page.authenticate();
await page.goto('http://lumtest.com/myip.json');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Try to use the prefered protocol before ip address and port.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--proxy-server=https://191.243.218.249:53281']
});
const page = await browser.newPage();
await page.authenticate();
await page.goto('http://lumtest.com/myip.json');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Related
I get the below error when trying to automate Zomato site with puppeteer. I've not been able to find much information about this error online. Can anyone help me in to know about this error?
My code:
const axios = require('axios');
const cheerio = require('cheerio');
const puppeteer = require("puppeteer");
console.log("before");
const link = "https://www.zomato.com/";
(async () => {
try{
const browser = await puppeteer.launch({
headless: false,
slowMo: 250,
args: ["--start-maximized"],
defaultViewport: null,
});
const page = await browser.newPage();
await page.goto(link,{waitUntil: 'domcontentloaded'});
await page.click(".sc-bke1zw-1.bcVYKA>a");
await browser.close();
}
catch(error) {
console.log(error);
}
})();
Error:
The goal is to obtain all product links from all pages in the pagination. So far I have managed to print information to the console with console.log (links). However, since I am completely new to this field and completely inexperienced, I have a problem how to pass some value back with the return command. return links.
With console.log(links) I get a warning: getLinks is not iterable
const puppeteer = require('puppeteer')
async function getLinks(){
const browser = await puppeteer.launch({headless: false, defaultViewport: null});
const page = await browser.newPage();
const url = "https://example.com/product-category?p=1&nidx"
await page.goto(url)
while(await page.$('.change-country-buttons > button:nth-child(1)')){
await page.waitForTimeout(2000);
await page.keyboard.press('ArrowDown');
await page.waitForSelector('.change-country-buttons');
await page.waitForTimeout(2000);
await page.click('.change-country-buttons > button:nth-child(1)');
await page.waitForTimeout(2000);
}
while(await page.$(".pagination .pagination--next")){
await page.waitForTimeout(2000);
await page.evaluate(() => {
document.querySelector(".pagination .pagination--next").scrollIntoView();
});
await page.waitForTimeout(1000);
await page.waitForSelector(".pagination .pagination--next")
await page.waitForTimeout(500);
await page.click('.pagination .pagination--next')
const links = await page.$$eval('.item__info > .mtc-link:nth-child(2)', (allAs) => { return allAs.map((a) => a.href) });
await page.waitForTimeout(1500);
console.log(links)
}
}
return links // Is returning links only form the first page and then the loop stops
I tried something with Promise.all () but it wasn't entirely clear to me how to do it.
Please help and be gentle as I am just starting to learn the basics
You need to create an array and push all the helmet links from each page onto it.
This tested successfully for me.
const puppeteer = require('puppeteer')
async function getLinks(){
const browser = await puppeteer.launch({headless: false, defaultViewport: null});
const page = await browser.newPage();
const url = "https://www.motocard.com/en/motorcycle-road-gear/helmets/precio_150-3200/full-face?p=1&nidx"
var all_links = [];
await page.goto(url);
while(await page.$('.change-country-buttons > button:nth-child(1)')){
await page.waitForTimeout(2000);
await page.keyboard.press('ArrowDown');
await page.waitForSelector('.change-country-buttons');
await page.waitForTimeout(2000);
await page.click('.change-country-buttons > button:nth-child(1)');
await page.waitForTimeout(2000);
}
while(await page.$(".pagination .pagination--next")){
await page.waitForTimeout(2000);
await page.evaluate(() => {
document.querySelector(".pagination .pagination--next").scrollIntoView();
});
await page.waitForTimeout(1000);
await page.waitForSelector(".pagination .pagination--next")
await page.waitForTimeout(500);
await page.click('.pagination .pagination--next')
const links = await page.$$eval('.item__info > .mtc-link:nth-child(2)', (allAs) => { return allAs.map((a) => a.href) });
await page.waitForTimeout(1500);
//console.log(links)
all_links.push(...links);
}
return all_links;
}
(async ()=>{
var links = await getLinks();
console.log('done');
console.log(links);
})();
i want to store puppeteer page into session to use in another middleware in express
here is my code in first middleware:
(async () => {
let solve;
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0)
await page.goto(URL, { waitUntil: 'domcontentloaded' });
await page.click('button.imeiInquiry');
const images = await page.$eval(('.captcha-image[src]'),node => node.src);
res.send({
type: 'img',
url: images,
});
req.session.page = page;
})();
and here is the code in 2nd middleware:
(async () => {
const page = await req.session.page;
res.send(await req.session.page.title);
await page.type('#CaptchaInputText', req.body.capchaNumber);
await page.type('#ImeiNumber', req.body.imei);
await page.click('.swal2-confirm')
})
but 2nd middleware doesnt work
This is the code I have given:
const puppeteer = require('puppeteer');
(async () => {
const baseUrl = 'example.com';
const browser = await puppeteer.launch({ headless: true});
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)
});
}
await page.goto(baseUrl);
await page.waitForSelector('[name="loginfmt"]');
await page.type('[name="loginfmt"]', 'abc#amazon.com');
await page.click('[type="submit"]');
delay(1000);
await page.authenticate({ username: `abc#amazon.com`, password: `abc#123` });
await page.click((`[data-row-id="111-222-333-444"]`));
await delay(1000);
await page.pdf(
{
path: "Z1.pdf",
printBackground: true,
width: '1300px',
height: '14200px'
}
)
browser.close();
})()
When inspected the page with document.querySelectorAll([data-row-id="111-222-333-444"]); it returned a NodeList array which consisted the details which I have been looking for.
However when tried the same via Puppeteer it terminates with an error saying "Error: No node found for selector: [data-row-id="111-222-333-444"]"
Tried using:
"const button= await page.$(([data-row-id="111-222-333-444"]);
button.click();"
I have been trying to fix this since a long time. It would be really helpful if I get a fix for this.
Try using this code:
const puppeteer = require('puppeteer');
(async () => {
const baseUrl = 'example.com';
const browser = await puppeteer.launch({ headless: true});
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
await page.goto(baseUrl);
await page.waitForSelector('[name="loginfmt"]');
await page.type('[name="loginfmt"]', 'abc#amazon.com');
await page.click('[type="submit"]');
await page.waitForTimeout(1000)
await page.authenticate({ username: `abc#amazon.com`, password: `abc#123` });
await page.waitForTimeout(5000)
await page.$(`[data-row-id="111-222-333-444"]`);
await page.click((`[data-row-id="111-222-333-444"]`));
await page.waitForTimeout(1000)
await page.pdf(
{
path: "Z1.pdf",
printBackground: true,
width: '1300px',
height: '14200px'
}
)
browser.close();
})()
If I go to https://investor.vanguard.com/mutual-funds/profile/VMMXX and execute document.querySelector("[data-ng-if='productSummaryTitle']").innerText from console, I get what I am expecting: Product summary.
But when I try to do the same with puppeteer, I get UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null at __puppeteer_evaluation_script__:3:83. What am I missing?
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false })
const page = await browser.newPage()
await page.goto('https://investor.vanguard.com/mutual-funds/profile/VMMXX')
const result = await page.evaluate(() => {
let myText = document.querySelector("[data-ng-if='productSummaryTitle']").innerText
return {
myText
}
})
console.log(result)
browser.close()
})()
You could wait for that selector first
const element = await page.waitForSelector('[data-ng-if='productSummaryTitle']');
const text = await element.evaluate(el => el.innerText);
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://investor.vanguard.com/mutual-funds/profile/VMMXX');
const element = await page.waitForSelector("[data-ng-if='productSummaryTitle']");
const text = await element.evaluate(el => el.innerText);
console.log(text);
await browser.close();
})();