0

im trying to get some data with post request with pupiteer. website handle post request by receving post like this:

_csrf=t3KdCwJjKXTxdlk99kEexjeKrOgtgMaMXQOJ8hcUkPvBA9g4UxlfA4AZaXPBE3CID8nDoUmzn-IIaL2KRSb2nw%3D%3D&Product%5BSerialNumber%5D=356333101810641

and here is my sorce code:

(async () => {

    //puppeteer.use(stealthPlugin())

    const args = [
        '--fast-start',
        '--incognito',
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-infobars',
        '--window-position=1,4',
        '--ignore-certifcate-errors',
        '--ignore-certifcate-errors-spki-list',
        '--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1'
    ];

    const browser = await puppeteerFirefox.launch({
        args,
        headless: false,
        slowMo: 5
    })

    const imei = req.params.imei;
    
    const devices = puppeteer.devices;
    const page = await browser.newPage();
    //await page.setDefaultNavigationTimeout(0)
    await page.setJavaScriptEnabled(true);
    
    await page.goto(URL);
    //await page.waitForNavigation({waitUntil: 'networkidle2'});
    await page.waitForSelector('#product-serialnumber');
    await page.type('#product-serialnumber', req.params.imei);
    await page.click('i.btnSearch-clicked1');

    const data = await page.$$eval('.table-bordered tbody tr td span', tds => tds.map((td) => {
        return td.innerText;
    }));




    const dataJOSN = {
        brand: data[0],
        model: data[1],
        imei1: data[2],
        imei2: data[3]
    }

    res.json(dataJOSN);

})();

how can i handle csrf field in post request. can i generate it with some library?

sinammd
  • 122
  • 1
  • 1
  • 9
  • I'm confused about what you're asking. What site are you working with? I don't see any POST request attempt in your code, so I'm not sure when you want to make one, but see [how do POST request in puppeteer?](https://stackoverflow.com/questions/47060534/how-do-post-request-in-puppeteer) which might help. – ggorlen Jul 30 '21 at 15:10
  • here is the website: https://hamyab24.ir/ – sinammd Jul 31 '21 at 05:47

0 Answers0