• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

php结合phantomjs实现网页全屏截图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

   百度刚好找到这个插件 ,其实还有不少类似的插件。但是觉得这个简单一点就拿来用了。(这个我是网上找的,只是拿来用。)

<?php
    if (isset($_GET[\'url\']))
    {
        set_time_limit(0);

        $url = trim($_GET[\'url\']);
        $filePath = md5($url).\'.png\';
        if (is_file($filePath))
        {
            exit($filePath);
        }

        $command = "phantomjs snap.js {$url} {$filePath}";
        @exec($command);

        exit($filePath);
    }
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>快照生成</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<style>
* {
    margin: 0;
    padding: 0;
}

form {
    padding: 20px;
}

div {
    margin: 20px 0 0;
}

input {
    width: 200px;
    padding: 4px 2px;
}

#placeholder {
    display: none;
}
</style>
</head>

<body>
    <form action="" id="form">
        <input type="text" id="url" />
        <button type="submit">生成快照</button>

        <div>
            <img src="" alt="" id="placeholder" />
        </div>
    </form>
    <script>
    $(function(){
        $(\'#form\').submit(function(){
            if (typeof($(this).data(\'generate\')) !== \'undefined\' && $(this).data(\'generate\') === true)
            {
                alert(\'正在生成网站快照,请耐心等待...\');
                return false;
            }

            $(this).data(\'generate\', true);
            $(\'button\').text(\'正在生成快照...\').attr(\'disabled\', true);

            $.ajax({
                type: \'GET\',
                url: \'?\',
                data: \'url=\' + $(\'#url\').val(),
                success: function(data){
                    $(\'#placeholder\').attr(\'src\', data).show();
                    $(\'#form\').data(\'generate\', false);
                    $(\'button\').text(\'生成快照\').attr(\'disabled\', false);
                }
            });

            return false;
        });
    });
    </script>
</body>
</html>

这个是js  放到phantomjs同已目录下面  

var page = require(\'webpage\').create();
var args = require(\'system\').args;

var url = args[1];
var filename = args[2];

page.open(url, function () {
    page.render(filename);
    phantom.exit();
});

我测试了下,大部分网站都能顺利截图,效果还不错,但是有一些登录以后才能访问的页面好像截取的只能是登录页,还有一些不能截取成功,一些图片加载的好像也截取不成功。

http://pan.baidu.com/s/1hAwii   程序下载

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
使用xcache加速PHP运行发布时间:2022-07-10
下一篇:
PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap