/export API
The /export API fetches a URL and streams the result in its native content type (HTML, PDF, image, etc.).
You can check the full Open API schema here.
Quick Start
- JSON payload
- cURL
- Javascript
- Python
- Java
- C#
{
"url": "https://example.com/"
}
curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/"
}'
import { writeFile } from 'fs/promises';
const TOKEN = "YOUR_API_TOKEN_HERE";
const url = `https://production-sfo.browserless.io/export?token=${TOKEN}`;
const headers = {
'Content-Type': 'application/json'
};
const data = {
url: "https://example.com/"
};
const exportPage = async () => {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('text/html')) {
const content = await response.text();
await writeFile('page.html', content);
console.log('Content saved as page.html');
} else {
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
await writeFile('page.html', buffer);
console.log('Content saved as page.html');
}
};
exportPage();
import requests
TOKEN = "YOUR_API_TOKEN_HERE"
url = f"https://production-sfo.browserless.io/export?token={TOKEN}"
headers = {
'Content-Type': 'application/json'
}
data = {
"url": "https://example.com/"
}
response = requests.post(url, headers=headers, json=data)
with open("page.html", "wb") as file:
file.write(response.content)
print("Content saved as page.html")
import java.io.*;
import java.net.http.*;
import java.net.URI;
public class ExportPage {
public static void main(String[] args) {
String TOKEN = "YOUR_API_TOKEN_HERE";
String url = "https://production-sfo.browserless.io/export?token=" + TOKEN;
String jsonData = """
{
"url": "https://example.com/"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonData))
.build();
try {
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
try (FileOutputStream fileOutputStream = new FileOutputStream("page.html")) {
fileOutputStream.write(response.body());
System.out.println("Content saved as page.html");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string TOKEN = "YOUR_API_TOKEN_HERE";
string url = $"https://production-sfo.browserless.io/export?token={TOKEN}";
string jsonData = @"
{
""url"": ""https://example.com/""
}
";
using var client = new HttpClient();
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try {
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var bytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("page.html", bytes);
Console.WriteLine("Content saved as page.html");
} catch (Exception ex) {
Console.WriteLine("Error: " + ex.Message);
}
}
}
Response
The API returns the content in its native format. For HTML pages, you'll receive the HTML content with Content-Type: text/html:
<!DOCTYPE html>
<html>
<head>
<title>Example Domain</title>
...
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples...</p>
</div>
</body>
</html>
For PDFs, images, or other binary content, the API returns the appropriate content type (e.g., application/pdf, image/jpeg) with a Content-Disposition: attachment header.
Additional Examples and Configuration
Parameters
The /export API accepts the following parameters:
Required Parameters
url(string) - The URL of the resource to export
Optional Parameters
headers(object) - Custom HTTP headers to send with the requestgotoOptions(object) - Navigation options (see Request Configuration)waitForEvent(object) - Wait for a specific event before proceedingwaitForFunction(object) - Wait for a specific function to return truewaitForSelector(object) - Wait for a specific selector to be presentwaitForTimeout(number) - Time in milliseconds to wait after page loadbestAttempt(boolean) - Whether to continue on errors. Default: falseincludeResources(boolean) - Whether to include all linked resources (images, CSS, JavaScript) in a zip file. Default: false
For detailed documentation on gotoOptions, waitForEvent, waitForFunction, waitForSelector, waitForTimeout, and bestAttempt parameters, see the Request Configuration page.
Handling Different Content Types
The /export API automatically detects and returns content in its native format. Here's how to handle different response types in your code:
HTML Content
const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('text/html')) {
const htmlContent = await response.text();
// Process HTML content
}
PDF Content
const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('application/pdf')) {
const arrayBuffer = await response.arrayBuffer();
const pdfBuffer = Buffer.from(arrayBuffer);
// Save or process PDF buffer
}
Binary Content (Images, etc.)
const response = await fetch(url, options);
const contentType = response.headers.get('content-type');
if (contentType?.includes('image/') || !contentType?.includes('text/')) {
const arrayBuffer = await response.arrayBuffer();
const binaryBuffer = Buffer.from(arrayBuffer);
// Save or process binary buffer
}
Export with Custom Navigation Options
- cURL
- Javascript
- Python
- Java
- C#
curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"gotoOptions": {
"waitUntil": "networkidle0",
"timeout": 60000
},
"waitForSelector": {
"selector": "h1",
"timeout": 5000
}
}'
import { writeFile } from 'fs/promises';
const TOKEN = "YOUR_API_TOKEN_HERE";
const url = `https://production-sfo.browserless.io/export?token=${TOKEN}`;
const headers = {
'Content-Type': 'application/json'
};
const data = {
url: "https://example.com/",
gotoOptions: {
waitUntil: "networkidle0",
timeout: 60000
},
waitForSelector: {
selector: "h1",
timeout: 5000
}
};
const exportPage = async () => {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
await writeFile('page.html', buffer);
console.log('Content saved as page.html');
};
exportPage();
import requests
TOKEN = "YOUR_API_TOKEN_HERE"
url = f"https://production-sfo.browserless.io/export?token={TOKEN}"
headers = {
'Content-Type': 'application/json'
}
data = {
"url": "https://example.com/",
"gotoOptions": {
"waitUntil": "networkidle0",
"timeout": 60000
},
"waitForSelector": {
"selector": "h1",
"timeout": 5000
}
}
response = requests.post(url, headers=headers, json=data)
with open("page.html", "wb") as file:
file.write(response.content)
print("Content saved as page.html")
import java.io.*;
import java.net.http.*;
import java.net.URI;
public class ExportPageWithOptions {
public static void main(String[] args) {
String TOKEN = "YOUR_API_TOKEN_HERE";
String url = "https://production-sfo.browserless.io/export?token=" + TOKEN;
String jsonData = """
{
"url": "https://example.com/",
"gotoOptions": {
"waitUntil": "networkidle0",
"timeout": 60000
},
"waitForSelector": {
"selector": "h1",
"timeout": 5000
}
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonData))
.build();
try {
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
try (FileOutputStream fileOutputStream = new FileOutputStream("page.html")) {
fileOutputStream.write(response.body());
System.out.println("Content saved as page.html");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string TOKEN = "YOUR_API_TOKEN_HERE";
string url = $"https://production-sfo.browserless.io/export?token={TOKEN}";
string jsonData = @"
{
""url"": ""https://example.com/"",
""gotoOptions"": {
""waitUntil"": ""networkidle0"",
""timeout"": 60000
},
""waitForSelector"": {
""selector"": ""h1"",
""timeout"": 5000
}
}
";
using var client = new HttpClient();
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try {
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var bytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("page.html", bytes);
Console.WriteLine("Content saved as page.html");
} catch (Exception ex) {
Console.WriteLine("Error: " + ex.Message);
}
}
}
Export with All Resources (Zip File)
When includeResources is set to true, the API returns a zip file containing the HTML and all linked resources (images, CSS, JavaScript):
- cURL
- Javascript
- Python
- Java
- C#
curl -X POST \
"https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"includeResources": true
}' \
--output "webpage.zip"
import { writeFile } from 'fs/promises';
const TOKEN = "YOUR_API_TOKEN_HERE";
const url = `https://production-sfo.browserless.io/export?token=${TOKEN}`;
const headers = {
'Content-Type': 'application/json'
};
const data = {
url: "https://example.com/",
includeResources: true
};
const exportPage = async () => {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
const buffer = await response.arrayBuffer();
await writeFile("webpage.zip", Buffer.from(buffer));
console.log("Page with resources saved as webpage.zip");
};
exportPage();
import requests
TOKEN = "YOUR_API_TOKEN_HERE"
url = f"https://production-sfo.browserless.io/export?token={TOKEN}"
headers = {
'Content-Type': 'application/json'
}
data = {
"url": "https://example.com/",
"includeResources": True
}
response = requests.post(url, headers=headers, json=data)
with open("webpage.zip", "wb") as file:
file.write(response.content)
print("Page with resources saved as webpage.zip")
import java.io.*;
import java.net.http.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ExportPageWithResources {
public static void main(String[] args) {
String TOKEN = "YOUR_API_TOKEN_HERE";
String url = "https://production-sfo.browserless.io/export?token=" + TOKEN;
String jsonData = """
{
"url": "https://example.com/",
"includeResources": true
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonData))
.build();
try {
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
Files.write(Paths.get("webpage.zip"), response.body());
System.out.println("Page with resources saved as webpage.zip");
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string TOKEN = "YOUR_API_TOKEN_HERE";
string url = $"https://production-sfo.browserless.io/export?token={TOKEN}";
string jsonData = @"
{
""url"": ""https://example.com/"",
""includeResources"": true
}
";
using var client = new HttpClient();
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try {
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var bytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("webpage.zip", bytes);
Console.WriteLine("Page with resources saved as webpage.zip");
} catch (Exception ex) {
Console.WriteLine("Error: " + ex.Message);
}
}
}
Response
The API returns a zip file with Content-Type: application/zip and Content-Disposition: attachment header:
HTTP/1.1 200 OK
Content-Type: application/zip
Content-Disposition: attachment; filename="webpage.zip"
[Binary zip file content containing HTML and all resources]