I need to get fullscreen shot of website by URL, is there any PHP programs for that or services, if not, is there any Java programs for that purpose?
问题:
回答1:
There are plenty of ways:
Use http://khtml2png.sourceforge.net/index.php?page=faq
Use webkit engine with some bindings for it: http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/
Use mozilla engine in batch mode: http://www.chimeric.de/blog/2007/1018_automated_screenshots_using_bash_firefox_and_imagemagick
回答2:
You need to have a special version of a browser to "render" the page after it's processed by PHP or Java.
You'll most-likely need to set up some custom automation scripts to hit a URL after you ping a server running windows, OSX or a Linux window manager.
There are services out there which will do screen shots for you.
http://www.browsercam.com
http://webthumb.bluga.net/home
to name a few.
回答3:
Litmus is a great online resource for this kind of thing; you can submit a URL and have it take full-page screenshots on the latest browsers. If you get a paid subscription or use it on weekends, you'll have access to test on all 22 of its browsers instead of just the most recent. I use this website all the time, I think it's phenomenal.
BrowserShots is also great, and it supports tons more browsers, but in my experience it's a lot slower too. It's good to use if you need to test some browser Litmus doesn't, though.
回答4:
The best solution for me: Use selenium webdriver And taking screenshot can be as simple as this:
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Testing {
public void myTest() throws Exception {
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"),
DesiredCapabilities.firefox());
driver.get("http://www.google.com");
// RemoteWebDriver does not implement the TakesScreenshot class
// if the driver does have the Capabilities to take a screenshot
// then Augmenter will add the TakesScreenshot methods to the instance
WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).
getScreenshotAs(OutputType.FILE);
}
}
Dont forget to use FireFoxDriver. HtmlUnitDriver wont work this way as its headless.
Darn easy!!
回答5:
You can also do it yourself if you had a dedicated server. The idea is to launch a X Server and a browser in fullscreen mode, to take a shot, and save it into an image file.
Depending of your utilisation (occasional or intensive), you can adapt the process (i.e. not killing X everytime, etc...) to make it faster.
回答6:
It's not clear from the question whether you're looking to do this programatically or manually. If manually: there is a great plug-in for Firefox called Abduction! that renders a page as an image. Otherwise, Kane's answers have it pretty much covered.
回答7:
I found out that CutyCapt is the most easiest solution to take screenshots and it will work in Windows and Linux.
Installinging in Windows:
Just download file and execute.
Installining in debian:
apt-get install cutycapt xvfb
and running:
xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/cutycapt --url=http://www.google.com --out=/home/screenshots/screenshot_name.png
回答8:
Try a headless browser. Any one of these should do it:
- PhantomJS -> uses 'Webkit' layout engine (Safari/Chromium)
- TrifleJS -> uses 'Trident' layout engine (Internet explorer)
- SlimerJS -> uses 'Gecko' layout engine (Firefox)
You can take a screenshot by using following javascript code (saved to file renderpage.js
):
var page = require('webpage').create();
page.open('http://en.wikipedia.org', function() {
page.render('wikipedia.png');
});
Then execute via command line:
> phantomjs.exe renderpage.js
This will create a file wikipedia.png
with your screenshot.