Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
Puppeteer / POST Request

I'm trying now since over 48 hours and googelt almost the whole web. My problem is that when use puppeteer the POST Request is not working - I tried many websites but the POST Form Action is not working. Can somebody help me?

File test.js Usage: node test.js

const puppeteer = require('puppeteer');
const randomUseragent = require('random-useragent');
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36';

(async () => { const browser = await puppeteer.launch({ args: ['--no-sandbox'] }) // headless: true,

const page = await browser.newPage()
    
await page.setViewport({
    width: 1920 + Math.floor(Math.random() * 100),
    height: 3000 + Math.floor(Math.random() * 100),
    deviceScaleFactor: 1,
    hasTouch: false,
    isLandscape: false,
    isMobile: false,
});

const userAgent = randomUseragent.getRandom();
const UA = userAgent || USER_AGENT;

await page.setUserAgent(UA);
await page.setJavaScriptEnabled(true);
await page.setDefaultNavigationTimeout(0);

await page.setRequestInterception(true);
page.on("request", interceptedRequest => {

        var data = {
            
            "method": "POST",
            "postData": "URLz=VIDEOURL"
        };
        interceptedRequest.continue(data);
    });
    
const response = await page.goto('https://fdown.net/download.php')
 //const responseBody = await response.text();
 
await page.screenshot({ path: 'affe.png', fullPage: true })
await browser.close()

})()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First you need to be able to do manually from a browser, in the developper tab's console window:

// see https://stackoverflow.com/questions/6396101/pure-javascript-send-post-data-without-a-form
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://fdown.net/download.php", true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
    if (this.readyState != 4) return;

    if (this.status == 200) {
        var data = this.responseText;

        // we get the returned data
        console.log(data)
    }
    else {
        console.warn("POST error");
    }


    // end of state change: it can be after some time (async)
};
xhr.send("URLz=VIDEOURL");

and then you can make puppeteer do it in the page using page.evaluate which runs code in the target page:

const postResult = await page.evaluate(() => {
    return new Promise((resolve, reject) => {
        // see https://stackoverflow.com/questions/6396101/pure-javascript-send-post-data-without-a-form
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "https://fdown.net/download.php", true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr.onreadystatechange = function () {
            if (this.readyState != 4) return;

            if (this.status == 200) {
                var data = this.responseText;

                // we get the returned data
                console.log(data);
                resolve(data);
            }
            else {
                // error
                reject(this)
            }

            // end of state change: it can be after some time (async)
        };
        xhr.send("URLz=VIDEOURL");
    });
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda