-2

I'm working on a way to detect defacement on my website. The idea is to crawl the whole website and for each page, take a screenshot or render the website as an image and compare it with the last time the page has been checked.

I'm looking for a way to convert a whole webpage (HTML, CSS, JS) into an image, like a screenshot, no matter the language is (but I would prefer Java, Python or C#)

I need it to be fast and usable on a server.

I already tried the folowing in Java:

  • CssBox, but the rendering isn't good enough (no JS)
  • Selenium Web Driver, but it's way too slow (Time to open firefox, display the page etc...) and not usable without GUI

I think a solution would be a kind of wrapper for a web engine but I didn't find anything about that (at least in Java). I've been told PhantomJS would fit for this need, is it right?

The perfect result would be to create something like that: http://www.page2images.com/home

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
thibon
  • 360
  • 2
  • 7
  • 19

4 Answers4

0

Use a browser which you can control via a script or command line options like phantomjs. The documentation contains examples how to make screenshots from URLs.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0

The website you linked offer some good rest API that perform the task: it's not a viable option for you?

0

Selenium is your best bet. Depending on your page content (ie. JS libraries, etc) it might take some time, but you could automate this with a script to run nightly via cron. Or using screen.

It has a rich language of assertions and simulated mouse events, and ways to regression-test and/or monitor the state of a set of pages.

Good luck.

tatlar
  • 3,080
  • 2
  • 29
  • 40
0

With no GUI, it's probably not possible to do something like this.

If you're not too tight on the GUI and related things, you can use the JavaFX Webview and take a screenshot of the node using the following code

WritableImage image = webView.snapshot(null, null);
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
....

References:

WebView#snapshot

SwingFXUtils#fromFXImage

Constant
  • 780
  • 1
  • 5
  • 19