Some advanced users may want to send POST/PUT requests in order to scrape forms and API endpoints directly. You can do this by sending a POST/PUT request through ScraperAPI. The return value will be stringified. So if you want to use it as JSON, you will need to parse it into a JSON object.
API ENDPOINT REQUEST
import fetch from'node-fetch';// Replace POST with PUT to send a PUT request insteadoptions = { method:'POST', url:'http://api.scraperapi.com/?api_key=APIKEY&url=http://httpbin.org/post', body:JSON.stringify({ foo:'bar' }), headers: {'Content-Type':'application/json', },}fetch(options).then(response => {console.log(response) }).catch(error => {console.log(error) })//For form dataoptions = { method:'POST', url:'http: //api.scraperapi.com/?api_key=${api_key}&url=http://httpbin.org/post', form: { foo:'bar' }, headers: {'Content-Type':'application/x-www-form-urlencoded', },}fetch(options).then(response => {console.log(response) }).catch(error => {console.log(error) })
constfetch=require('node-fetch');options = { method:'POST', url:'http://async.scraperapi.com/jobs', headers: {'Content-Type':'application/json', },// The data for the target site body:JSON.stringify({ apiKey:'API_KEY', url:'https://httpbin.org/anything',// Replace POST with PUT to send a PUT request instead method:'POST', headers: {"content-type":"application/x-www-form-urlencoded"}, body:"foo=bar" }),}fetch(options).then(console.log).catch(console.error)