这是一个互联网页面的URL。我需要获取此页面的屏幕截图(无论在哪个浏览器中)。
我需要一个脚本(PHP、Python(甚至Django框架)),它接收URL(字符串)并在退出时输出屏幕截图文件(文件gif、png、jpg)。
更新:
我需要动态创建一个页面,在该页面的对面将放置具有相同URL的页面的屏幕截图。
这是一个互联网页面的URL。我需要获取此页面的屏幕截图(无论在哪个浏览器中)。
我需要一个脚本(PHP、Python(甚至Django框架)),它接收URL(字符串)并在退出时输出屏幕截图文件(文件gif、png、jpg)。
更新:
我需要动态创建一个页面,在该页面的对面将放置具有相同URL的页面的屏幕截图。
为什么你需要编写脚本,而不是使用另一个网站的服务呢?
例如,你可以查看我正在使用的WebSnapr http://www.websnapr.com/
或者尝试一下http://www.google.ro/search?ie=UTF-8&q=website+thumbnail看看是否有其他符合你需求的选项。
var page = require('webpage').create();
page.open('http://github.com/', function() {
page.render('github.png');
phantom.exit();
});
phantomjs github.js
//SOLUTION 1
<?php
$link = "http://example.com";
$googlePagespeedData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$link&screenshot=true");
$googlePagespeedData = json_decode($googlePagespeedData, true);
$screenshot = $googlePagespeedData['screenshot']['data'];
$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
$show_link = "<a href='$link'><img src=\"data:image/jpeg;base64,".$screenshot."\" /></a>";
echo $show_link;
//SOLUTION 2
$name = 'test';
$googlePagespeedData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$link&screenshot=true");
$googlePagespeedData = json_decode($googlePagespeedData, true);
$screenshot = base64_decode($googlePagespeedData['screenshot']['data']);
$data = str_replace('_','/',$googlePagespeedData['screenshot']['data']);
$data = str_replace('-','+',$data);
$decoded = base64_decode($data);
file_put_contents('myfolder/'.$name.'.jpg',$decoded);
$file_name = "$name.jpg";
/*
-- IMPORTANT INFORMATION -- READ BELOW --
Choose how to proceed!
1. Use the above to display screenshots of links = longer processing time for multiple links.
2. Save image to a file, reference the saved image = more disk space needed if multiple links.
Note the trade off between processing time and disk space, if you're on a shared hosting platform with a small disk space limit and envisage or already have a lot of users (forums beware) you may want to consider a bigger hosting plan or even a dedicated server.
*/
?>
<img src='http://zenithwebtechnologies.com.au/thumbnail.php?url=www.subway.com.au'>
你可以像我一样使用Shotbox API
这是法语,但是很快就能明白: