Skip to content

Instantly share code, notes, and snippets.

@gokusenz
Created June 5, 2020 18:28
Show Gist options
  • Save gokusenz/7328ccfef6bc00f3457b2f9d62fd519c to your computer and use it in GitHub Desktop.
Save gokusenz/7328ccfef6bc00f3457b2f9d62fd519c to your computer and use it in GitHub Desktop.
puppeteer post
// Used for serializing POST parameters from an object
const querystring = require('querystring');
// ...
const browser = await puppeteer.launch();
const page = await browser.newPage();
let postData = {a: 1, b: 2};
await page.setRequestInterception(true);
page.once('request', request => {
var data = {
'method': 'POST',
'postData': querystring.stringify(postData),
'headers': {
...request.headers(),
'Content-Type': 'application/x-www-form-urlencoded'
},
};
request.continue(data);
// Immediately disable setRequestInterception, or all other requests will hang
page.setRequestInterception(false);
});
const response = await page.goto('https://www.example.com/');
# https://stackoverflow.com/questions/47060534/how-do-post-request-in-puppeteer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment