zoukankan      html  css  js  c++  java
  • phantomjs

    phantomjs    (http://javascript.ruanyifeng.com/tool/phantomjs.html)

    有时,我们需要浏览器处理网页,但并不需要浏览,比如生成网页的截图、抓取网页数据等操作。PhantomJS的功能,就是提供一个浏览器环境的命令行接口,你可以把它看作一个“虚拟浏览器”,除了不能浏览,其他与正常浏览器一样。它的内核是WebKit引擎,不提供图形界面,只能在命令行下使用,我们可以用它完成一些特殊的用途。

    PhantomJS是二进制程序,需要安装后使用。

    webpage模块是PhantomJS的核心模块,用于网页操作。

    var page = require('webpage').create();
    
    page.open('http://slashdot.org', function (s) {
      console.log(s);
      phantom.exit();
    });
    只要接收到服务器返回的结果,PhantomJS就会报告网页打开成功,而不管服务器是否返回404或500错误。
    open方法默认使用GET方法,与服务器通信,但是也可以使用其他方法
    var webPage = require('webpage');
    var page = webPage.create();
    var settings = {
      operation: "POST",
      encoding: "utf8",
      headers: {
        "Content-Type": "application/json"
      },
      data: JSON.stringify({
        some: "data",
        another: ["custom", "data"]
      })
    };
    
    page.open('http://your.custom.api', settings, function(status) {
      console.log('Status: ' + status);
      // Do other things here...
    });
    evaluate方法用于打开网页以后,在页面中执行JavaScript代码。


    等等。。。方法可参见文档

  • 相关阅读:
    【UVa 1592】Database
    【UVa 400】Unix ls
    【UVa 136】Ugly Numbers
    【UVa 540】Team Queue
    【Uva 12096】The SetStack Computer
    【POJ 1050】To the Max
    【UVa 156】Ananagrams
    【UVa 10815】Andy's First Dictionary
    [HNOI/AHOI2018]转盘
    CF46F Hercule Poirot Problem
  • 原文地址:https://www.cnblogs.com/cina33blogs/p/8808025.html
Copyright © 2011-2022 走看看