Author Topic: Grab screenshot of any webpage using online API  (Read 3705 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Grab screenshot of any webpage using online API
« on: July 25, 2020, 03:11:06 pm »
You may want to show a screenshot of a website in your programs (for whatever reason). This will allow you to do so:
Go to https://screenshotlayer.com/ and make a free account.
Run the attached exe to see a demo but don't run it 100 times as it has my API key in it.

 
urlshot.png


Use the below code with your API key to grab the screenshot:



Code: QB64: [Select]
  1.  
  2. a = URLScreenShot("https://qb64.org/portal", "1920x1080", "720")
  3.  
  4. FUNCTION URLScreenShot& (website AS STRING, viewport AS STRING, imagewidth AS STRING)
  5.     DIM URL AS STRING
  6.     DIM URLFile AS STRING
  7.     DIM URLshot AS STRING
  8.     DIM a%
  9.     URLFile = "urlshot.jpg"
  10.     SHELL _HIDE "curl " + CHR$(34) + "http://api.screenshotlayer.com/api/capture?access_key=YOURACCESSKEYHERE&url=" + website + "&viewport=" + viewport + "&width=" + imagewidth + CHR$(34) + " -o " + URLFile
  11.     OPEN URLFile FOR BINARY AS #1
  12.     IF LOF(1) <> 0 THEN
  13.         URLScreenShot = _LOADIMAGE(URLFile, 32)
  14.         CLOSE #1
  15.         KILL URLFile
  16.     ELSE
  17.         CLOSE #1
  18.         KILL URLFile
  19.     END IF
* urlshot.exe (Filesize: 2.22 MB, Downloads: 196)
Shuwatch!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Grab screenshot of any webpage using online API
« Reply #1 on: July 25, 2020, 03:58:46 pm »
_SCREENIMAGE works for me, and it'd be easy to write a program to size/move a box to capture a portion.

Why make it more complicated by calling external programs?



It works better if you plug it in.

FellippeHeitor

  • Guest
Re: Grab screenshot of any webpage using online API
« Reply #2 on: July 25, 2020, 04:04:21 pm »
To use _SCREENIMAGE to capture a screenshot of a website means you'll have to call an external program - your preferred browser in this case.

With Spriggsy's method you'd be using screenshotlayer.com's API to do that job for ya. If I understood the post above correctly, the exe he's providing is merely the code in the codebox compiled with his API key in it, which allows one to run the example without having to create an account with the website unless they'd want to.
« Last Edit: July 25, 2020, 04:08:47 pm by FellippeHeitor »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Grab screenshot of any webpage using online API
« Reply #3 on: July 25, 2020, 04:13:11 pm »
@Richard Frost Precisely what Fellippe was saying. My exe is just using the code in the post with my API key already in it.
Shuwatch!

FellippeHeitor

  • Guest
Re: Grab screenshot of any webpage using online API
« Reply #4 on: July 25, 2020, 04:20:28 pm »
BTW, Spriggsy, you may wanna store your key in a more concealed way within your exe. I'm sending you a private message with it - just as a proof of concept.

All literal strings/data within an EXE are stored as literals within the exe itself - the resources section of it.

I'd do something like this to generate a string of sensitive data - and still no warranties it can't be retrieved:

Code: QB64: [Select]
  1. a$ = "string I don't want people to have access to, but still want it in my exe"
  2.  
  3. FOR i = 1 TO LEN(a$)
  4.     IF LEN(b$) THEN b$ = b$ + " + "
  5.     b$ = b$ + "CHR$(" + STR$(ASC(a$, i)) + ")"
  6.  
  7.  

This code will parse your secret string and copy this to the clipboard:

Code: QB64: [Select]
  1. CHR$( 115) + CHR$( 116) + CHR$( 114) + CHR$( 105) + CHR$( 110) + CHR$( 103) + CHR$( 32) + CHR$( 73) + CHR$( 32) + CHR$( 100) + CHR$( 111) + CHR$( 110) + CHR$( 39) + CHR$( 116) + CHR$( 32) + CHR$( 119) + CHR$( 97) + CHR$( 110) + CHR$( 116) + CHR$( 32) + CHR$( 112) + CHR$( 101) + CHR$( 111) + CHR$( 112) + CHR$( 108) + CHR$( 101) + CHR$( 32) + CHR$( 116) + CHR$( 111) + CHR$( 32) + CHR$( 104) + CHR$( 97) + CHR$( 118) + CHR$( 101) + CHR$( 32) + CHR$( 97) + CHR$( 99) + CHR$( 99) + CHR$( 101) + CHR$( 115) + CHR$( 115) + CHR$( 32) + CHR$( 116) + CHR$( 111) + CHR$( 44) + CHR$( 32) + CHR$( 98) + CHR$( 117) + CHR$( 116) + CHR$( 32) + CHR$( 115) + CHR$( 116) + CHR$( 105) + CHR$( 108) + CHR$( 108) + CHR$( 32) + CHR$( 119) + CHR$( 97) + CHR$( 110) + CHR$( 116) + CHR$( 32) + CHR$( 105) + CHR$( 116) + CHR$( 32) + CHR$( 105) + CHR$( 110) + CHR$( 32) + CHR$( 109) + CHR$( 121) + CHR$( 32) + CHR$( 101) + CHR$( 120) + CHR$( 101)

Then when you use that in your code, it'll be stored in a much "safer" way.

Our friends in this forum sure will have even more clever ways to suggest (I'm also looking forward to new ideas on this).
« Last Edit: July 25, 2020, 04:25:40 pm by FellippeHeitor »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Grab screenshot of any webpage using online API
« Reply #5 on: July 25, 2020, 04:32:04 pm »
@FellippeHeitor I wasn't too worried about it. Most of these APIs I won't be using much anyways. They're mostly for proof of concept. I'm not going to be too heartbroken if someone steals them and uses them. I can always make a new account or get a new API key if it gets leaked. No issue.
Shuwatch!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Grab screenshot of any webpage using online API
« Reply #6 on: July 25, 2020, 10:39:54 pm »
I've captured screenshots of websites using _SCREENIMAGE after _SCREENHIDE, although of course the browser was already running. 

Having read the code, now I see the difference.  You capture the image without "going there" with a browser.  So you could
automate all sorts of things, like getting just the current temperature from a weather site - until the site changes the location
on the screen! 

Your APIs are very interesting, and advanced. 
It works better if you plug it in.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Grab screenshot of any webpage using online API
« Reply #7 on: July 26, 2020, 02:45:33 pm »
Shuwatch!