Are you looking to take screenshots of webpages in bulk using Google Sheets? There are multiple ways of doing this –
- Using No Code tools such as Zapier/Make (or Integromat)/Pabbly Connect
- Using Google Sheet’s App Script Code
In this guide, we will provide a step-by-step guide to taking screenshots in bulk for website URLs that are in Google Sheets. You do not need to be a developer to set this up and even if you’re not a coder, you can just follow these steps to generate screenshots of webpages in bulk.
- On a Google Sheet, load the webpage URLs in column A as per the below format
2. On the Google Sheet’s menubar, click on “Extensions” -> “App Script”
3. Copy the below script code and paste it in your Google App Script Code Editor
function captureScreenshot() {
// Get the active spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Get the active sheet
var sheet = spreadsheet.getActiveSheet();
// Get the range of data (assuming data starts from row 2)
var dataRange = sheet.getRange(2, 1, sheet.getLastRow() - 1, 2);
// Get the values in the range
var data = dataRange.getValues();
// Iterate through each row
for (var i = 0; i < data.length; i++) {
// Check if column B is empty and column A is not empty
if (data[i][0] && !data[i][1]) {
// Prepare the request body
var requestBody = {
"url": data[i][0],
"generate_img_url": true,
"wait_till": 2
};
// Prepare options for the API request
var options = {
"method": "post",
"headers": {
"CLIENT-API-KEY": "5e1ff0175bb74151b96f27f5e573cb82"
},
"contentType": "application/json",
"payload": JSON.stringify(requestBody)
};
// Make the API request
var response = UrlFetchApp.fetch("http://api.htmlcsstoimg.com/api/v1/generateImage", options);
// Parse the JSON response
var responseData = JSON.parse(response.getContentText());
// Get the image URL from the response
var imageUrl = responseData.image_url;
// Update column B with the image URL
sheet.getRange(i + 2, 2).setValue(imageUrl);
}
}
}
4. Generate your Free API Key for HTML to Image API from here and replace in the code as indicated below
5. Click on “Run” icon on top bar
6. Authorize Google Permissions
7. Now, run the script again and wait for the execution to be completed
8. Check your Google Sheet, the screenshot URLs are updated in column B
If you need help with any of these steps, please feel free to email us at support@htmlcsstoimg.com
Leave a Reply