Created
June 5, 2020 18:28
-
-
Save gokusenz/7328ccfef6bc00f3457b2f9d62fd519c to your computer and use it in GitHub Desktop.
puppeteer post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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