导航首页 » 技术教程 » pagepeeker网站截图工具使用教程 两种API调用

pagepeeker网站截图工具使用教程 两种API调用

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 发布在 技术教程 栏目,部分信息由互联网转载而来,如有信息标注为原创内容,未经许可,禁止转载。

原文地址:https://www.diryy.com/post-83.html

文章评论
火山猎人: 2023-5-21 16:40
这个网站做得不错,非常值得学习,收录的各行业网站都是比较精致的,写的文章也比较有参考价值,网站已经收藏了,希望能收录更多好的网站,写更多好的文章,最值得点赞的是网站首页聚合了百度、搜狗、360和神马等搜索引擎,方便搜索内容。
头像
梦想家: 2023-5-15 08:05
太好了,《pagepeeker网站截图工具使用教程 两种API调用》写的东西正好是我想要学习技术教程方面内容,对我的知识提升帮助很大啊。
头像
神秘人: 2023-5-8 12:05
请问一下我想在“技术教程”栏目发布一篇软文怎么办,没看到有自主发布文章的入口,是不是需要站长手动发布,另外再问一下在贵站发布一篇软文需要收费么,具体是多少钱一篇呢?可以打包发布么?
头像
神奇女侠: 2023-4-18 09:34
《pagepeeker网站截图工具使用教程 两种API调用》这篇文章的观点和我不太一样,但是我认为作者的论据还是很有说服力的。文章的主题非常有意思,让人想要深入了解更多相关的内容。文章的结构也非常合理,让人容易跟随作者的思路。