Skip to content

Instantly share code, notes, and snippets.

@inetkiller
Created June 4, 2013 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inetkiller/5705112 to your computer and use it in GitHub Desktop.
Save inetkiller/5705112 to your computer and use it in GitHub Desktop.
<?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