金名网(JINNAME.COM)高权重域名抢注 过期删除域名预订抢注服务
45
2024-02-26
pagepeeker.com是一个网站截图服务提供商,它提供了一个API接口,可以让开发者通过调用该接口来获取指定网站的截图。
该API接口的功能包括:
获取指定网站的截图
可以设置截图的尺寸和质量
可以设置截图的格式(PNG或JPEG)
可以设置截图的缓存时间,以减少重复请求
第一种接口,提供给别人输入网址一键获取网址截图:
前端代码:
<!DOCTYPE html>
<html>
<head>
<title>PagePeeker API Demo</title>
</head>
<body>
<h1>PagePeeker API Demo</h1>
<form action="get_screenshot.php" method="post">
<label for="url">URL:</label>
<input type="text" name="url" id="url" required>
<br>
<label for="width">Width:</label>
<input type="number" name="width" id="width" value="1024" required>
<br>
<label for="height">Height:</label>
<input type="number" name="height" id="height" value="768" required>
<br>
<label for="format">Format:</label>
<select name="format" id="format">
<option value="png">PNG</option>
<option value="jpeg">JPEG</option>
</select>
<br>
<input type="submit" value="Get Screenshot">
</form>
</body>
</html>
接口代码:
<?php
// PagePeeker API endpoint
define('API_ENDPOINT', 'http://api.pagepeeker.com/v2/thumbs.php');
// PagePeeker API key
define('API_KEY', 'YOUR_API_KEY');
// Get the URL and other parameters from the form
$url = $_POST['url'];
$width = $_POST['width'];
$height = $_POST['height'];
$format = $_POST['format'];
// Build the API request URL
$request_url = API_ENDPOINT . '?key=' . API_KEY . '&size=' . $width . 'x' . $height . '&format=' . $format . '&url=' . urlencode($url);
// Get the screenshot from the API
$screenshot = file_get_contents($request_url);
// Output the screenshot
header('Content-Type: image/' . $format);
echo $screenshot;
?>
第二种接口:使用url传递参数,自动获取网页截图
API接口:命名为:xxxx.php,加入如下代码:
<?php
// PagePeeker API endpoint
define('API_ENDPOINT', 'http://api.pagepeeker.com/v2/thumbs.php');
// PagePeeker API key
define('API_KEY', 'YOUR_API_KEY');
// Get the URL from the URL parameter
$url = $_GET['url'];
// Build the API request URL
$request_url = API_ENDPOINT . '?key=' . API_KEY . '&size=1024x768&format=jpeg&url=' . urlencode($url);
// Get the screenshot from the API
$screenshot = file_get_contents($request_url);
// Output the screenshot
header('Content-Type: image/jpeg');
echo $screenshot;
?>
然后在前端调用即可,代码如下:
<img src="https://www.xxxx.com/xxxx.php?url=网站域名" alt="网页快照" id="" />
本文由 易用导航 于 2023-05-25 发布在 技术教程 栏目,部分信息由互联网转载而来,如有信息标注为原创内容,未经许可,禁止转载。