Rendering Javascript
Learn to scrape JavaScript-rendered pages using ScraperAPI in Ruby. Enable headless browser rendering with render=true for dynamic content, SPAs, and JS-heavy sites.
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.
Pass the JavaScript rendering parameter within the URL:
API REQUEST
require 'net/http'
require 'uri'
require 'json'
# Define parameters including headers
params = {
api_key: "<YOUR_API_KEY>",
url: "http://httpbin.org/ip",
render: true
}
# URI for the API endpoint (note: use HTTPS)
uri = URI('https://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)
# Create a GET request
req = Net::HTTP::Get.new(uri)
req['Accept'] = 'application/json'
req['X-MyHeader'] = '123'
# Create an HTTPS connection
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# Perform the HTTPS request
website_content = http.request(req)
# Output the response body
puts website_content.bodyPROXY MODE
SDK Method
Pass the parameter in the headers:
API REQUEST
PROXY MODE
SDK Method
Last updated
Was this helpful?

