Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Automatic Screenshots in Apps Script

About this Tutorial

This tutorial has no description yet.

Video Transcript

<div>00:00 So let's create automatic screenshots in our Google Sheets. So we can select Learn how to use the query select clause effectively in your Google Sheets. Opens in new tab URLs and get that screenshot. We're going to use screenshot1.com.<br>00:10 It has a hundred free API calls, I believe. Um, and there's a lot of reasons we will do this. One, maybe we want to create our own archive of a particular page.<br>00:22 Like, my front page is Jira.

It's bettersheets.co, and yes, I can go to, like, Internet Archive and see the past results.<br>00:28 But for some marketing purposes or quick screenshots, maybe I want to screenshot it every week because I'm doing some kind of experiment.<br>00:36 Or, I want to look at competitor pricing. Um, I'm going to look at their pricing page. I want a screenshot of that.<br>00:42 I want to save that screenshot.

Maybe I want to analyze it later or grab a snippet each week and just have it available.<br>00:50 Or, I want to look at, like, Google search results and see exactly what's going on, not just scrape the results, but literally see, okay, go to the page, see the results, see if there's AI stuff going on.<br>01:03 I want to, like, look at it. Or, I want to, like, screenshot a Google Sheet, for example.

Anywhere where Discover how to filter data using the query where clause in Google Sheets. Opens in new tab you can go to the URL, you can grab a image Understand how to work with images in your Google Sheets. Opens in new tab of that page, and you want to save it, this is going to be a very helpful tutorial for you.<br>01:18 Uh, we're going to actually do two things in this video.

We are going to grab the screenshot, which I've made a video of this before, exclusive to members.<br>01:29 But now, I'm going to try to automate this, because I want to say, hey, go to this Webflow.com http://www slash price thing, every week, once a week, at the exact same time, and grab a screenshot, and save all of those into a drive.<br>01:45 Alright, we are going to start from blank, we are going to try to just get the screenshot using the screenshot API, Screenshot One API.<br>01:53 You need to go to Screenshot One, you need to go and get your access key, that is all you need from Screenshot one.<br>02:00 Every day.

Everything else will be in this video. So we are going to call this AutoScreenshot. I'm going to create a function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab called GetScreenshot.<br>02:17 I'm going to go to some target URL, because we are going to use a few different URLs. I want to say what is the websites URL that we're actually going to get the screenshot of.<br>02:27 We're going to need the API URL. We're going to need the URL of the actual cached image Understand how to work with images in your Google Sheets. Opens in new tab . Uh, we're going to end up at the end with some kind of URL for even the Google Drive saved image Understand how to work with images in your Google Sheets. Opens in new tab .<br>02:40 So this target URL is called target URL, not just URL.

Above this, as a blanket, sort Master sorting techniques to organize your data in Google Sheets. Opens in new tab of. Overall variable, I'm going to write API key and you put your API key here.<br>02:55 I'm putting mine. And of course I'm going to regenerate mine after I make this video, but you just put yours there in quotes and all caps API key.<br>03:03 We can now use that anywhere in our function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab as a variable.

I just want to make that clear that this is where Discover how to filter data using the query where clause in Google Sheets. Opens in new tab you can edit this.<br>03:11 If you are a BetterSheets fan, member, and you're watching this on BetterSheets, this sheet, exactly this sheet, is down below.<br>03:19 You can just copy it and use it and edit it as you wish. So we're going to need the API URL.<br>03:26 And this is going to be That's the entire API URL. And then we're going to need to encode this.

The reason is we want to make it so that we can actually access it through a URL fetch app.<br>03:49 Like, it's an, like, if we write some spaces here or things, they're going to, we want to change them into, literally, a URL can use that letter.<br>04:00 So we're going to say, encode encoded URL equals encode URI component and put our target URL here.<br>04:17 So the URL that we're grabbing from our sheet, just in case it's Oddly, maybe we're copying and pasting it from somewhere, we just want to make sure that it is correctly accessible to put into a URI or URL.<br>04:37 And now we're going to take this API URL, our target URL, and we're going to combine Learn how to merge cells for better data presentation in Google Sheets. Opens in new tab them into a single URL that, that, that, then we can use URLFetchApp Explore the URL Fetch App and how to use it in Google Apps Script. Opens in new tab to go and get.<br>04:53 So basically we're going to call this API.

If you haven't worked with APIs before, I would recommend going and doing Spreadsheet Understand the basics of spreadsheets and their functionalities. Opens in new tab Automation 101.<br>05:03 That course will take you through very basic steps of coding and get you to APIs and explain all about APIs very quick, not quickly, but very quickly.<br>05:13 Basically, we just need to go to a URL and get the response there. But the URL that we want is going to be pretty crazy.<br>05:22 We're going to call this full URL. And I'm going to put it in backticks because we're going to fill this with variables.<br>05:31 Basically, we have first this API URL.

So we're going to do dollar sign Learn the significance of the dollar sign in formulas and functions. Opens in new tab . And curly brackets. And put that API URL.<br>05:43 That's going to be the start of our URL. Then we're going to put a question mark, access key. And this is all documented on screenshot1's API, how to access their API.<br>05:57 I'm just doing it for you here. Now we're going to equals, we're going to put in our API key. But we can't just do this, just copy and paste API key.<br>06:06 We have to do the same thing we did just before, which is put dollar sign Learn the significance of the dollar sign in formulas and functions. Opens in new tab curly brackets around it.

This is called interpolation, and we're saying, hey, yes, we're going to give you this text, this text, but we're going to grab this text from somewhere else.<br>06:22 Okay, now we need to say URL. Equals, and do you get the last, do you already, a step ahead of me, we're going to put this encoded URL in there.<br>06:37 So we're taking the API key, we're taking the API URL, and the encoded URL, we're all putting it together, but we have to have a few more little pieces of information.<br>06:47 So we're going to put an ampersand.

I'm going to say format Discover various formatting options to enhance your Google Sheets. Opens in new tab equals jpeg, we're going to say ampersand cache equals true, we're going to say ampersand cache underscore TTL, this is just saying how long do you want the cache to be available for, this is like seconds, two five nine two zero zero zero, that's<br>07:12 a lot of seconds, Thanks. That's 43,000 minutes, 720 hours, it's about, let's see, 60 divided by 24, that's about 30 days of seconds.<br>07:30 And we need one more thing, response type equals JSON.

So we're saying, hey, when we tell you this URL that we're going to go to, we have the correct access key, what kind of response do we want back?<br>07:47 We want JSON back. JSON is a very easy-to-read-for-computers kind of language. So this computer and this function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab is going to be able to read this JSON.<br>08:01 And we're going to tell it how to read it.

We're going to say, turn JSON capitalized, and this is saying, this is a, JSON capitalized is a function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab inside of Apps Script Get introduced to Apps Script and its capabilities for automating tasks. Opens in new tab that allows us to parse JSON.<br>08:14 What we're going to say is, URLFetchApp Explore the URL Fetch App and how to use it in Google Apps Script. Opens in new tab .fetch, and go grab that full URL, and then just on the other, between these two parentheses, getContentText, and then outside we're going to say .cacheURL.<br>08:35 Now what all this is doing is saying, hey, go fetch that URL that we've just created, get back whatever, get back whatever content text you have that tells what the response is, then parse it, but then only, of all of the information you're giving us, only tell us what is the cache URL.<br>08:54 There's a whole lot of other information when you get this response, but honestly all we need right, right now, all we need is this URL.<br>09:02 We could deal with response codes and say, okay, if it's 200, give us the cache URL, if it's something else, give us the error Learn how to troubleshoot common errors in Google Sheets. Opens in new tab , but for this particular video, we just care about the URL.<br>09:13 And this function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab , getScreenshot, is going to go to that target URL at the API and give us back some image Understand how to work with images in your Google Sheets. Opens in new tab .<br>09:22 Actually, it's going to give us back, sorry, it is going to give us back not the image Understand how to work with images in your Google Sheets. Opens in new tab , but the URL to the image Understand how to work with images in your Google Sheets. Opens in new tab .<br>09:28 So I'm going to hit save, and I'm going to go try it.

I'm going to say getScreenshot and see what happens.<br>09:35 So, we have to now nothing equals getScreenshot. I'm going to put this URL in here, bettersheets.co, and I'm going to hit enter and see, do we get an error Learn how to troubleshoot common errors in Google Sheets. Opens in new tab ?<br>09:47 Probably. So we say, okay, this is all saying basically it didn't work. But, let's see if we can do something else.<br>09:59 Let's Let's see, maybe it is a permissions. Let's hit run. I'm going to hit continue. I do believe, maybe it is, that it is just this HTTPS there.<br>10:37 That we just need a full URL. That is exactly the issue.

It was just that we needed the exact full URL.<br>10:42 HTTPS, slash, slash, and it works. So we can actually go to this URL and see what is at this URL is the image Understand how to work with images in your Google Sheets. Opens in new tab .<br>10:50 All we're doing here in B is saying, wrapping that URL around image Understand how to work with images in your Google Sheets. Opens in new tab . Let's get screenshot for A3. We're going to get an error Learn how to troubleshoot common errors in Google Sheets. Opens in new tab .<br>11:02 Let's do HTTPS. Boom. It works. And let's do the next couple. Just to make sure it's working for all of these URLs.<br>11:14 These kinds of things. Actually, I'm, I'm really interested in this Google search.

Oh, funny enough, this Google search gave it an error Learn how to troubleshoot common errors in Google Sheets. Opens in new tab .<br>11:23 It's, it's doing this thing that Google has done now recently. It's like, you need to authorize it. You're a human.<br>11:29 So, that's not working. But the screenshot of a Google sheet is working. Pretty cool, right? That basically we can do this.<br>11:36 Yes, Google search is not working. But only because it's not really a human doing the screenshot. All right, let's save this.<br>11:45 So, now that we know that this screenshot works, we need the full URL. Let's save it to a drive.

So, we'll create another function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab , Then save screenshot to drive.<br>12:02 And what this is going to do is, we don't necessarily want this, like, in a sheet like this, like, we're just going to list the URL and then go grab the image Understand how to work with images in your Google Sheets. Opens in new tab .<br>12:11 We know the URL we want, let's say this, like, webflow pricing or bettersheets.co slash pricing, right? Uhm, we know that URL and we want to go to it every week.<br>12:24 So we're going to say, const cacheURL equals getScreenshot, we're going to put in quotes anything.<br>12:52 You can have that trailing, whatever.

So we're going to grab the screenshot here. Now what's interesting is we save this cache for 30 days.<br>13:05 So you might want to decrease that amount. If you do, then you'll get a new screenshot. However, in my particular case, screenshot one only gives you, like, a hundred for free.<br>13:20 Then it starts charging you if you want to be charged, you know, depends on how many screenshots you really need.<br>13:26 You need them every week, every day, every month, every two months, whatever that is. We're going to create a blob.<br>13:37 Why do I say blob? I say blob.

Because that's how files are saved in Google Drive. So we're going to say URLFetchApp Explore the URL Fetch App and how to use it in Google Apps Script. Opens in new tab .fetch.<br>13:48 Go grab that cache URL. And again, we're not getting We're getting the response URL of screenshot one.<br>14:02 And then we're saying get blob. And we want to set the name. This is very particular because we want a consistent screenshot name hyphen and then I'm going to add dollar sign Learn the significance of the dollar sign in formulas and functions. Opens in new tab and do some interpolation here of new date.<br>14:26 And I'm going to just say dot to ISO string Understand string manipulation and its applications in Google Sheets. Opens in new tab .

This is just saying, hey, create a new timestamp Learn how to work with timestamps for better data tracking. Opens in new tab , but call it a ISO string Understand string manipulation and its applications in Google Sheets. Opens in new tab .<br>14:41 And then at the end, dot JPEG. Okay, so we're just saying put a date and time here of whatever this file is.<br>14:50 Now, the folder. This folder situation is very complicated. Drive sort Master sorting techniques to organize your data in Google Sheets. Opens in new tab of makes it weird. We do const folders equals drive app dot get folders by name.<br>15:08 And we're going to search for Better Sheets Screenshots. You can name this anything you want. You just need to know what is the folder name.<br>15:18 Yes, you can create a folder and then put the name here. However, you don't have to.

I'll show you why.<br>15:25 We're going to let folder. That's just a variable that says, here's a random variable, just a blank variable, not random, blank, called folder, and if folders.hasNext, get it.<br>15:39 Yes, folders.

Go up to this folders, do .hasNext, and if that's true, meaning there is a folder there, then we're going to do folder equals folders.next.<br>15:54 So, we're saying, hey, if you go and get all the folders by name and there is a next one, that next one, that's the name of the folder, and that's the folder we want one.<br>16:03 However, else, actually put this on a new line, there is an else, we have to deal with else, meaning if this folder doesn't exist and it's false here, doesn't have a next one.<br>16:20 Let's go make it. We'll say folder equals drive app.

Create folder and we're going to name it the exact same.<br>16:35 So basically all of this is saying, hey, go look for the folder called BetterSheets screenshots. If it does exist, give us back that folder.<br>16:48 If it doesn't exist, go create it. And now we're going to return, so this is the end of our function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab here, we're going to return folder.createFile, blob, this blob up here, this is the JPEG we're saving, and we're going to get the URL.<br>17:15 Now, where Discover how to filter data using the query where clause in Google Sheets. Opens in new tab do we want to get this?

We can call this a variable, we can just say, variable, screenshotURL equals this, and instead of a return, let's append to somewhere, let's create a sheet, called saved, Thank you.<br>17:39 And we're going to just append here, in the A column, this saved URL.<br>17:51 We're going to get this URL. So, we're going to say, spreadsheetApp Explore the features of the spreadsheet app in Google Sheets. Opens in new tab .getActiveSpreadsheet, getSheetByName, saved, dot, appendRow Discover how to append rows efficiently in your Google Sheets. Opens in new tab , and what are we going to append?<br>18:04 The screenshot URL. In, and this is, let's bring this up to the top, this is in square brackets.

Okay, so every time this runs, it's going to append, right here, a new URL.<br>18:22 Maybe let's say date, as well. Let's put a, the new date here. So how do we do that? Let's go back to our, here, and we're going to do a comma, new date, and it'll have a timestamp Learn how to work with timestamps for better data tracking. Opens in new tab .<br>18:42 So let's run save screenshot to drive. We're going to select Learn how to use the query select clause effectively in your Google Sheets. Opens in new tab it up here, save everything, or click save project to drive.<br>18:49 Let's hit run, we may need more authorization Understand the authorization process for accessing Google Sheets. Opens in new tab . Waiting patiently to see if we have any errors.<br>19:12 Let's go. We have a URL. We have a timestamp Learn how to work with timestamps for better data tracking. Opens in new tab . Great.

And, if we go to that URL, it is saved.<br>19:24 Let's go to our drive as well. And there's BetterSheet screenshots, and there it is. So if we run this again, right now, obviously this site hasn't changed, but if we run it again, it's doing all of its work.<br>19:43 There's another Google Drive file. Fantastic, right? So how do we automate this? Let's go back to our Apps Script Get introduced to Apps Script and its capabilities for automating tasks. Opens in new tab . We have two functions Get familiar with various functions available in Google Sheets. Opens in new tab , GetTheScreenshot and SaveTheScreenshot.<br>19:57 SaveTheScreenshot actually uses GetScreenshot, which is cool, which sometimes, you like to put it like this.

Sometimes, you can do it like that.<br>20:10 SaveScreenshots at the top. But how do we automate? Let's go over to the left side, go to Triggers. On the bottom right, there's a big blue button called Add Trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab .<br>20:21 Choose which function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab to run. This is a drop-down menu that shows all of our functions Get familiar with various functions available in Google Sheets. Opens in new tab . If you have other functions Get familiar with various functions available in Google Sheets. Opens in new tab in your Thank you.<br>20:27 sheet, you're going to have to find it, and we're going to use SaveScreenshot to drive. Select Learn how to use the query select clause effectively in your Google Sheets. Opens in new tab EventSource. It's going to be time-driven.<br>20:35 Select Learn how to use the query select clause effectively in your Google Sheets. Opens in new tab type of timer. I want to do it every month.

On the first of the month.<br>20:46 Great. And I'll do it at 5 to 6 a.m. These are all things you can change yourself, and now we have a Apps Script Get introduced to Apps Script and its capabilities for automating tasks. Opens in new tab .<br>21:00 Trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab , an automation that has been created. If we want to delete this and we don't want to save these particular screenshots anymore, click the three buttons to the right and delete trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab .<br>21:15 Delete forever. If you want more than one, we need to do a couple things. This is only one site.

Save, you can call this Save Better Sheets.<br>21:28 Then we can copy this Save Better sheets, paste it, underneath it, and say Save Webflow Pricing. And we're done. Let's go get that URL over here somewhere.<br>21:46 And we can change the URL right there. And now we have a whole new function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab that's saving this. Now let's save.<br>21:58 And if we go over to triggers, we can create two triggers. One that saves time. Gives better sheets, and one that saves web flow.<br>22:06 Add trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab . And now we have two functions Get familiar with various functions available in Google Sheets. Opens in new tab here.

They are both using this Git screen shot, which is totally fine.<br>22:14 And actually, really nice functionality here. But if you don't want to be copying all of this stuff, there is one other way.<br>22:28 We can do this. Save URL to drive and put in URL here. And instead of putting this as a, ah, text, we can just put it as a variable URL.<br>22:43 And we can save this URL and make that the variable there. Every time we save this URL, we may want to rename this folder, okay?<br>22:59 So these are going to be all the screenshots of everything. Maybe you want a unique Discover how to find unique values in your data sets in Google Sheets. Opens in new tab folder for each URL.

So let's try to do that.<br>23:07 We can put, instead of these quotes, we can put backticks. instead of better sheet screenshots. Let's call it screenshots4, and do interpolation as well here.<br>23:31 And literally the URL that it is, is going to be in the name of the folder. Let's see if that works.<br>23:39 So, we need, We need a trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab to trigger Learn about triggers and how to automate tasks in Google Sheets. Opens in new tab this. So, we actually need to create another function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab , savebettersheets, put that in quotes, and run save URL to drive, and do HTTPS, bettersheets.com.<br>24:04 Now, much simpler function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab to run.

We can call this savewebflowpricing, again grab this URL.<br>24:23 So, what's going on here is we are creating a little function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab that just says, hey, go to this URL, I'll save to drive and use this URL.<br>24:32 However, I want to, I want to share Understand how to share your Google Sheets with others effectively. Opens in new tab one cool thing we can do here. We can add multiple variables, save this URL.<br>24:38 So, we can say, here's the URL, here's the folder name, and here we say, BetterSheets.co. And here, with, for Webflow, we say, Webflow Pricing.<br>25:01 And instead of screenshots for save this URL, we put that folder name there.

So, this is a really cool way to say, hey, yes, I want to save the Webflow, I want to save this URL, and I want to call the folder this.<br>25:14 So, now, every time we run this, it's going to save that URL, but use a different name for the folder name.<br>25:21 Pretty cool, right? And then, all we have to do is automate this function Get to know functions and how they can enhance your Google Sheets experience. Opens in new tab for Save Better Sheets.

All we have to do is automate this Save Webflow Pricing.<br>25:31 We can even test this out, just to see if this is work, working, and see if we have a Webflow Pricing, uh, folder.<br>25:40 So, it looks like it all worked fine, and here it is, screenshots for Webflow Pricing, And every time we run this, Save Webflow Pricing, if we've automated it, it's going to just add to this drive folder.<br>26:17 Pretty cool, right?

This is awesome that we can do automatic screenshotting from Google Sheets with Screenshot One, and do it in a way where Discover how to filter data using the query where clause in Google Sheets. Opens in new tab we're saving this to a particular file.<br>26:28 Google Drive folder. Again, if you're watching this not on BetterSheets, on BetterSheets.co, all members have access to this exact file.<br>26:39 Go grab it. Become a member of BetterSheets today. Thanks for those who are already members of BetterSheets.</div>

Courses