php phantomjs 截屏,phantomjs截图

php phantomjs 截屏,phantomjs截图废话不多说,直接上代码。功能:随便截取一个url页面:https://www.baidu.com/s?word=phantomjs+%E6%88%AA%E5%9B%BE&tn=43061099_196_hao_pg&ie=utf-8&ssl_sample=hao_1phantomjs的js环境test.jssystem=require(‘system’)address…

大家好,又见面了,我是你们的朋友全栈君。

废话不多说,直接上代码。

功能:随便截取一个url页面:

https://www.baidu.com/s?word=phantomjs+%E6%88%AA%E5%9B%BE&tn=43061099_196_hao_pg&ie=utf-8&ssl_sample=hao_1

phantomjs的js环境test.js

system = require(‘system’)

address = system.args[1];//获得命令行第二个参数 接下来会用到

//console.log(‘Loading a web page’);

var page = require(‘webpage’).create();

var url = address;

//console.log(url);

page.open(url, function (status) {

//Page is loaded!

if (status !== ‘success’) {

console.log(‘Unable to post!’);

} else {

//console.log(page.content);

//var title = page.evaluate(function() {

// return document.title;//示范下如何使用页面的jsapi去操作页面的 www.oicqzone.com

// });

//console.log(title);

console.log(‘ok’);

page.render(‘e:/phantomjs/example.png’);

}

phantom.exit();

});

java调用外部程序代码:

public class PhantomTest {

public static String getAjaxCotnent(String url) throws IOException {

Runtime rt = Runtime.getRuntime();

Process p = null;

try {

p = rt.exec(“D:/phantomjs-2.0.0-windows/bin/phantomjs.exe e:/phantomjs/test.js “+url);

} catch (IOException e) {

e.printStackTrace();

}

InputStream is = p.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(is));

StringBuffer sbf = new StringBuffer();

String tmp = “”;

while((tmp = br.readLine())!=null){

sbf.append(tmp);

}

System.out.println(“a”+sbf);

System.out.println(sbf.toString());

return sbf.toString();

}

public static void main(String[] args) throws IOException {

getAjaxCotnent(“https://www.baidu.com/s?word=phantomjs+%E6%88%AA%E5%9B%BE&tn=43061099_196_hao_pg&ie=utf-8&ssl_sample=hao_1”);

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159373.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • JVM垃圾回收机制

    JVM垃圾回收机制

    2021年11月12日
    38
  • Android 4.0开发之GridLayOut布局实践

    Android 4.0开发之GridLayOut布局实践在上一篇教程中http://blog.csdn.net/dawanganban/article/details/9952379,我们初步学习了解了GridLayout的布局基本知识,通过学习知道,GridLayout可以用来做一个象TableLayout这样的布局样式,但其性能及功能都要比tablelayout要好,比如GridLayout的布局中的单元格可以跨越多行,而tablelayout则不

    2022年5月28日
    36
  • vmware10.0密钥_windows10永久激活密钥

    vmware10.0密钥_windows10永久激活密钥VMwareWorkstation是功能最强大的热门虚拟机软件,现已自带原生简体中文。用户可在在虚拟机同时运行各种操作系统,进行开发、测试、演示和部署软件,虚拟机中复制服务器、台式机和平板环境,每个虚拟机可分配多个处理器核心、千兆字节的主内存和显存。VMwareWorkstation™11延续了VMware的传统,即提供技术专业人员每天在使用虚拟机时所依赖的领先功能和性能。借

    2025年11月16日
    1
  • Django(53)二次封装Response

    Django(53)二次封装Response前言有时候我们使用drf的Response,会发现默认返回的格式不太友好,每次我们都需要写入以下的格式returnResponse({"status":0,"

    2022年7月29日
    13
  • JS 暂时性死区「建议收藏」

    JS 暂时性死区「建议收藏」JS暂时性死区ES6暂时性死区引用ES6暂时性死区只要块级作用域内存在let命令,它所声明的变量就“绑定”(binding)这个区域,不再受外部的影响。vartmp=123;if(true){tmp=’abc’;//ReferenceErrorlettmp;}上面代码中,存在全局变量tmp,但是块级作用域内let又声明了一个局部变量tmp,导致后…

    2022年6月30日
    24
  • 【JWPlayer】官方JWPlayer去水印步骤「建议收藏」

    【JWPlayer】官方JWPlayer去水印步骤「建议收藏」JWPlayer免费版去水印

    2022年7月2日
    32

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号