Rendering Javascript

If you are crawling a page that requires you to render the javascript on the page to scrape the data you need, then we can fetch these pages using a headless browser. To render javascript, simply set render=true and we will use a headless Google Chrome instance to fetch the page. This feature is available on all plans.

  • API REQUEST

import fetch from 'node-fetch';

fetch('http://api.scraperapi.com/?api_key=APIKEY&url=http://httpbin.org/ip&render=true')
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
  • PROXY MODE

const axios = require('axios');
axios.get('http://httpbin.org/ip', {
  method: 'GET',
  proxy: {
    host: 'proxy-server.scraperapi.com',
    port: 8001,
    auth: {
      user: 'scraperapi.render=true',
      password: 'APIKEY'  
    },
    protocol: 'http'
  }
})
  .then(response => {
    console.log(response)
  })
  .catch(error => {
    console.log(error)
  });
  • SDK Method

const request = require('request-promise');

options = {
  method: 'GET',
  url: 'http://httpbin.org/ip',
  proxy: 'http://scraperapi.render=true:APIKEY@proxy-server.scraperapi.com:8001'
}
request(options)
  .then(response => {
      console.log(response)
  })
  .catch(error => {
      console.log(error)
  })

Last updated