With this API you can take screenshots of any page. You just have to send a GET request to https://api.scrapingdog.com/screenshot
with the below-given parameters.
cURL Python Nodejs PHP Ruby Java
Copy curl "https://api.scrapingdog.com/screenshot?api_key=6103077e467766765f5803ed2df7bc8&url=https://www.scrapingdog.com"
Copy import requests
api_key = "6103077e467766765f5803ed2df7bc8"
url = "https://api.scrapingdog.com/screenshot"
params = {
"api_key": api_key,
"url": "https://www.scrapingdog.com"
}
response = requests.get(url, params=params)
if response.status_code == 200:
with open("screenshot.png", "wb") as f:
f.write(response.content)
else:
print("Failed to capture a screenshot.")
Copy const axios = require('axios');
const fs = require('fs');
const apiKey = '6103077e467766765f5803ed2df7bc8';
const url = 'https://api.scrapingdog.com/screenshot';
const params = {
api_key: apiKey,
url: 'https://www.scrapingdog.com',
};
axios
.get(url, { params, responseType: 'stream' })
.then((response) => {
if (response.status === 200) {
response.data.pipe(fs.createWriteStream('screenshot.png'));
} else {
console.error('Failed to capture a screenshot.');
}
})
.catch((error) => {
console.error('Error:', error.message);
});
Copy <?php
$apiKey = '6103077e467766765f5803ed2df7bc8';
$url = 'https://api.scrapingdog.com/screenshot';
$targetUrl = 'https://www.scrapingdog.com';
$data = [
'api_key' => $apiKey,
'url' => $targetUrl,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false) {
echo 'Error: ' . curl_error($ch);
} else {
file_put_contents('screenshot.png', $response);
echo 'Screenshot saved as screenshot.png';
}
curl_close($ch);
?>
Copy require 'net/http'
api_key = '6103077e467766765f5803ed2df7bc8'
target_url = 'https://www.scrapingdog.com'
uri = URI('https://api.scrapingdog.com/screenshot')
uri.query = URI.encode_www_form(api_key: api_key, url: target_url)
response = Net::HTTP.get_response(uri)
if response.code.to_i == 200
# Save the screenshot as screenshot.png
File.open('screenshot.png', 'wb') do |file|
file.write(response.body)
end
puts "Screenshot saved as screenshot.png"
else
puts "Error: #{response.code} - #{response.message}"
end
Copy import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class ScreenshotAPI {
public static void main(String[] args) {
String apiKey = "6103077e467766765f5803ed2df7bc8";
String apiUrl = "https://api.scrapingdog.com/screenshot";
String targetUrl = "https://www.scrapingdog.com";
try {
HttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(apiUrl + "?api_key=" + apiKey + "&url=" + targetUrl);
HttpResponse response = httpclient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
// Get the response stream
InputStream is = response.getEntity().getContent();
// Save the screenshot to a file
FileOutputStream fos = new FileOutputStream("screenshot.png");
int inByte;
while ((inByte = is.read()) != -1) {
fos.write(inByte);
}
is.close();
fos.close();
System.out.println("Screenshot saved as screenshot.png");
} else {
System.out.println("Error: " + response.getStatusLine().getStatusCode() + " - " + response.getStatusLine().getReasonPhrase());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}