Hello.

How can I get a screen site, there is some kind of API? I rummaged on the Internet everywhere for this money asking. Can I do this function myself and how?

Thank you in advance!

  • It's strange how you were looking for if, on request, the site screenshot gives you a lot of free services. Moreover, you can find a bunch of extensions in any browser - Alexey Shimansky
  • @ Alexey Shimansky You misunderstood me, I have a website in which there are a lot of links, and I need to add a button to these links so that users can follow the link to see a screenshot of the site. - Hakob Shaghikyan
  • @Alexander There is created a screen of this site, which is open in the browser, I need to get it without opening the site. - Hakob Shaghikyan
  • And why it is impossible to take screenshots in advance and upload to the site and so that the user has already looked at these pictures? If your site would be guided by showing screenshots of sites of any page, I would understand. But if only one screen for one link is shown - it is easier to download them and not to suffer - Alexey Shimansky

2 answers 2

I would, in your place, use phantomjs or its analogs. A simple example:

phantomjs test.js http://zub96.ru test.png 

Add the following code to the test.js file:

 var page = require('webpage').create(), system = require('system'), address, output, size; if (system.args.length < 3 || system.args.length > 5) { console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); phantom.exit(1); } else { address = system.args[1]; output = system.args[2]; page.viewportSize = { width: 1920, height: 600 }; if (system.args.length > 3 && system.args[2].substr(-4) === ".png") { size = system.args[3].split('*'); page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' } : { format: system.args[3], orientation: 'portrait', margin: '1cm' }; } if (system.args.length > 4) { page.zoomFactor = system.args[4]; } page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { page.render(output); phantom.exit(); }, 200); } }); } 

At the output we get the png file test.png Image created by phantojs , and then you can process it as you need.

  • This is exactly what I looked at, thanks a lot for the example, I will let you know if something happens. - Hakob Shaghikyan
  • Can this all be done automatically? - Hakob Shaghikyan
  • Can. Add, in the script of adding the site to the folder, call phantomjs or use ready-made libraries, such as PHP PhantomJS , for other languages ​​too. - Andrew Hobbit
  • And there is some kind of instruction for newbies, everything is not so clear there - Hakob Shaghikyan
  • And what are your difficulties? With phantom, integration or some kind of library? Do you have a service as organized? - Andrew Hobbit

In firefox, in the inspector, there is a button to take a screenshot. You may need to write a browser extension and programmatically call this function.

enter image description here

  • This can only be done with mozila firefox, right? - Hakob Shaghikyan
  • yes only with mozila firefox. it still seems to be in chrome, this function also appeared, but I am not 100% sure I can’t find it myself. - spectre_it
  • But for this you need to open the same site, and I need to get a screen without opening it - Hakob Shaghikyan