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
require 'net/http'
require 'json'
## Replace POST with PUT to send a PUT request instead
params = {
:api_key => "APIKEY",
:url => "http://httpbin.org/anything"
}
uri = URI('http://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)
website_content = Net::HTTP.post(uri, { "foo" => "bar"}.to_json, "Content-Type" => "application/json")
print(website_content.body)
## For form data
params = {
:api_key => "APIKEY",
:url => "http://httpbin.org/anything"
}
uri = URI('http://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)
req = Net::HTTP::Post.new(uri)
req.set_form_data('foo' => 'bar')
website_content = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
print(website_content.body)