Screenshot Capture

Last updated

Last updated
curl -i --request GET \
--url 'https://api.scraperapi.com?api_key=API_KEY&screenshot=true&url=https://example.com/'import requests
target_url = 'https://example.com/'
# Replace the value for api_key with your actual API Key.
api_key = 'API_KEY'
request_url = (
f'https://api.scraperapi.com?'
f'api_key={api_key}'
f'&screenshot=true'
f'&url={target_url}'
)
response = requests.get(request_url)
# Print response headers
print("Response headers:")
for k, v in response.headers.items():
print(f"{k}: {v}")
print("\nResponse body:")
print(response.text)import request from 'node-fetch';
// Replace the value for api_key with your actual API Key.
const url = 'http://api.scraperapi.com/?api_key=API_KEY&screenshot=true&url=https://example.com/';
request(url)
.then(response => {
// Print response headers
console.log('Response headers:');
response.headers.forEach((value, key) => {
console.log(`${key}: ${value}`);
});
// Existing behavior
console.log(response);
})
.catch(error => {
console.error(error);
});<?php
// Replace the value for api_key with your actual API Key.
$url = "https://api.scraperapi.com?api_key=API_KEY&screenshot=true&url=https://example.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Print response headers
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
} else {
print_r($response);
}
curl_close($ch);
?>require 'net/http'
params = {
# Replace the value for api_key with your actual API Key.
api_key: "API_KEY",
screenshot: "true",
url: "https://example.com/"
}
uri = URI('https://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
# Print response headers
puts res.to_hash
puts res.bodyimport java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
// Replace the value for api_key with your actual API Key.
String apiKey = "API_KEY";
String targetUrl = "https://example.com/";
String scraperApiUrl =
"https://api.scraperapi.com?api_key=" + apiKey
+ "&screenshot=true"
+ "&url=" + targetUrl;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(scraperApiUrl))
.GET()
.build();
HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());
// Print response headers
System.out.println(response.headers().map());
System.out.println(response.body());
}
}curl -X POST \
-H "Content-Type: application/json" \
-d '{
"apiKey": "API_KEY",
"url": "https://example.com/",
"apiParams": {
"screenshot": "true"
}
}' \
"https://async.scraperapi.com/jobs"import requests
r = requests.post(
url='https://async.scraperapi.com/jobs',
json={
# Replace the value for api_key with your actual API Key.
'apiKey': 'API_KEY',
'screenshot': 'true',
'url': 'https://example.com/'
}
)
print(r.text)import axios from 'axios';
(async () => {
try {
const { data } = await axios({
method: 'POST',
url: 'https://async.scraperapi.com/jobs',
headers: { 'Content-Type': 'application/json' },
data: {
// Replace the value for api_key with your actual API Key.
apiKey: 'API_KEY',
url: 'https://example.com',
apiParams: {
screenshot: 'true'
}
}
});
console.log(data);
} catch (error) {
console.error(error);
}
})();<?php
$payload = json_encode([
// Replace the value for api_key with your actual API Key.
"apiKey" => "API_KEY",
"url" => "https://example.com",
"apiParams" => [
"screenshot" => "true"
]
]);
$ch = curl_init("https://async.scraperapi.com/jobs");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
?>require 'net/http'
require 'json'
uri = URI('https://async.scraperapi.com/jobs')
payload = {
# Replace the value for api_key with your actual API Key.
"apiKey" => "API_KEY",
"url" => "https://example.com",
"apiParams" => {
"screenshot" => "true"
}
}
response = Net::HTTP.post(uri, payload.to_json, "Content-Type" => "application/json")
puts response.bodyimport java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://async.scraperapi.com/jobs");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
String payload = "{"
// Replace the value for api_key with your actual API Key.
+ "\"apiKey\": \"API_KEY\","
+ "\"url\": \"https://example.com\","
+ "\"apiParams\": {"
+ "\"screenshot\": \"true\""
+ "}"
+ "}";
try (OutputStream os = conn.getOutputStream()) {
os.write(payload.getBytes(StandardCharsets.UTF_8));
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getResponseCode() == 200 ? conn.getInputStream() : conn.getErrorStream()
))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) response.append(line);
System.out.println(response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}curl -i --proxy 'http://scraperapi.screenshot=true:[email protected]:8001' \
-k \
'https://example.com/'import requests
# Replace the value for api_key with your actual API Key.
proxies = {
"http": "http://scraperapi.screenshot=true:[email protected]:8001"
}
r = requests.get('http://example.com/', proxies=proxies, verify=False)
# Print response headers
print(r.headers)
print(r.text)import axios from 'axios';
axios.get('http://example.com/', {
method: 'GET',
proxy: {
host: 'proxy-server.scraperapi.com',
port: 8001,
auth: {
username: 'scraperapi.screenshot=true',
// Replace the value for password with your actual API Key.
password: 'API_KEY'
},
protocol: 'http'
}
})
.then(response => {
// Print response headers
console.log(response.headers)
console.log(response.data);
})
.catch(error => {
console.log(error);
});<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/");
curl_setopt($ch, CURLOPT_PROXY,
// Replace the value for api_key with your actual API Key.
"http://scraperapi.screenshot=true:[email protected]:8001"
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>require 'httparty'
HTTParty::Basement.default_options.update(verify: false)
response = HTTParty.get('http://example.com/', {
http_proxyaddr: "proxy-server.scraperapi.com",
http_proxyport: 8001,
http_proxyuser: "scraperapi.screenshot=true",
# Replace the value for http_proxypass with your actual API Key.
http_proxypass: "API_KEY"
})
# Print response headers
puts response.headers
results = response.body
puts resultsimport java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.security.cert.X509Certificate;
public class Main {
public static void main(String[] args) {
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}
}, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
String apiKey = "API_KEY"; // Replace with your actual API Key.
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"scraperapi.screenshot=true", apiKey.toCharArray()
);
}
});
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
System.setProperty("https.proxyHost", "proxy-server.scraperapi.com");
System.setProperty("https.proxyPort", "8001");
HttpsURLConnection conn = (HttpsURLConnection) new URL("https://example.com/").openConnection();
conn.setRequestMethod("GET");
BufferedReader in;
if (conn.getResponseCode() >= 400) {
in = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
} else {
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
}
StringBuilder resp = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
resp.append(line).append("\n");
}
in.close();
// Print response headers
System.out.println(conn.getHeaderFields());
System.out.println(resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}