现在的位置: 首页 > web前端 > 正文

PHP+CutyCapt实现抓取保存网页URL的快照图片

2019年11月18日 web前端 ⁄ 共 1269字 ⁄ 字号 评论关闭

  PHP +CutyCapt实现抓取保存网页URL的快照图片。php利用CutyCapt抓取网页高清图片快照。原理和其他搜索引擎的抓取网页快照原理一样。

  1、准备工具

  CutyCapt文件;

  php开发运行环境。

  2、方法/步骤

  //设置运行不超时;

  header("Content-Type:text/html; charset=utf-8");set_time_limit(0);

  //设置抓取网址

  $url="http://www.nongyejing.com";

  //设置图片名称(以当前时间戳命名)

  $time=time();

  //设置图片输出地址

  $outdir = 'E:/BaseServer/htdocs/curlImg/'.$time.".png";

  //CutyCapt绝对路径

  $path = 'E:/BaseServer/htdocs/CutyCapt.exe';

  //命令

  $cmd = "$path --url=$url --out=$outdir";

  完整代码:

  header("Content-Type:text/html; charset=utf-8");

  set_time_limit(0);

  //抓取网址

  $url="http://www.nongyejing.com/static/php/2014/1222/75.html";

  //设置图片名称

  $time=time();

  //设置图片输出地址

  $outdir = 'E:/BaseServer2/htdocs/curlImg/'.$time.".png";

  //CutyCapt绝对路径

  $path = 'E:/BaseServer2/htdocs/CutyCapt.exe';

  //命令

  $cmd = "$path --url=$url --out=$outdir";

  //执行命令

  exec($cmd);

  echo "图片抓取成功!";

  补充:报错:exec() has been disabled for security reasons in 意思是exec() 函数已经由于安全原因被禁止。

  说明:这是因为在 php.ini 配置文件里面有disable_function 这个选项 后面是禁用的php函数,打开PHP.INI,找到disable_function=phpinfo,passthru,exec,system,popen,escapeshellcmd,escapeshellarg,shell_exec

  解决方法:

  打开php安装路径 打开php.ini文件

  则把disable_function=phpinfo,passthru,exec,system,popen,escapeshellcmd,escapeshellarg,shell_exec

  里面的 exec, 删除 并保存 重启php-fcgi

  我使用的是lnmp一键安装包,只要/root/lnmp reload即可。

  其他参数报错的话,解决办法相同。

【上篇】
【下篇】

抱歉!评论已关闭.