Created
June 4, 2013 13:41
-
-
Save codesaler/5706010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_GET['url'])) { | |
$url = rawurldecode(trim($_GET['url'])); | |
if (empty($url)) | |
return; | |
if (substr($url, 0, 4) != 'http') | |
$url = "http://{$url}"; | |
require_once 'PHPWebDriver/__init__.php'; | |
$wd_host = 'http://localhost:4444/wd/hub'; | |
$WebDriver = new PHPWebDriver_WebDriver($wd_host); | |
$session = $WebDriver->session('firefox'); | |
$session->window()->postSize(array('width' => 1366, 'height' => 768)); | |
$session->open($url); | |
$img = $session->screenshot(); | |
$data = base64_decode($img); | |
$session->close(); | |
header("content-type:image/png"); | |
header("Cache-control: max-age=60"); | |
header("Content-Length: " . strlen($data)); | |
echo $data; | |
} else { | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<p> | |
<input type="text" id="url" name="url" placeholder="请输入网址" style="width: 600px"/> | |
<input type="button" id="go" value="Go" onclick="return go();" /> | |
</p> | |
<img id="img" src="" onload="done()"/> | |
<script type="text/javascript"> | |
function go() { | |
document.getElementById("go").value = "Loading"; | |
document.getElementById("go").setAttribute("disabled", "disabled"); | |
document.getElementById("img").setAttribute("src", ""); | |
var url = encodeURIComponent(document.getElementById("url").value); | |
document.getElementById("img").setAttribute("src", "?url=" + url); | |
return false; | |
} | |
function done() { | |
document.getElementById("go").value = "Go"; | |
document.getElementById("go").removeAttribute("disabled"); | |
} | |
</script> | |
</body> | |
</html> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment