PHP中怎么利用CutyCapt抓取保存网页URL

这篇文章给大家介绍PHP中怎么利用CutyCapt抓取保存网页URL,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

  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即可。

关于PHP中怎么利用CutyCapt抓取保存网页URL就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。