日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

phantomjs介绍

發(fā)布時(shí)間:2025/4/16 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 phantomjs介绍 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一. phantomjs定義

? ? 無界面的webkit引擎,它為我們提供了一個(gè)命名行的瀏覽器接口,可以幫助我們生成網(wǎng)頁的截圖以及抓取網(wǎng)頁內(nèi)容。

二.?phantomjs 下載及安裝

  • 下載地址:http://phantomjs.org/download.html
  • 直接解壓安裝并且配置path環(huán)境變量,執(zhí)行如下命令查看配置是否正確。 #phantomjs --version1.9.2
  • ?

    三.簡(jiǎn)單demo

    ? ?通過Phantomjs運(yùn)行簡(jiǎn)單的hello world demo如下

  • 創(chuàng)建簡(jiǎn)單的hello.js文件,其內(nèi)容如下:
    console.log('Hello, world!'); phantom.exit();
  • 在命令行執(zhí)行如下代碼: #phantom hello.jshello world

    ?

  • ?

    ? ?通過Phantomjs抓取網(wǎng)頁的列子:

  • 創(chuàng)建如下page.js文件,內(nèi)容如下 var page = require('webpage').create();page.open('http://www.baidu.com',function(){page.render('baidu.png');phantom.exit(); });

    ?

  • 執(zhí)行如下命令:

    #phantom page.js

    其生成的圖片結(jié)果如下:??

  • ? ? ? ? ?

    ?

    ? ? ?例子3:loadspeed.js

    ? ? ??

    var page = require("webpage").create(),system = require('system'),t, address;if(system.args.length===1) {console.log('usage: loadinspeed.js <some URL>');phantom.exit();}t = Date.now();address = system.args[1];console.log(address);page.open(address, function(status){console.log(status);if(status !== 'success'){console.log('faild to load the address');}else {t = Date.now() - t;console.log('loading time ' + t +' msec');}phantom.exit();});

    執(zhí)行結(jié)果如下

    D:\demo>phantomjs loadspeed.js http://www.baidu.com http://www.baidu.com success loading time 513 msec

    ?

    通過evaluate()獲取頁面要素:

    var page = require('webpage').create();page.open("http://phantomjs.org/quick-start.html", function(status) {var title = page.evaluate(function() {return document.title;});console.log('Page title is ' + title); });

    運(yùn)行結(jié)果

    # hantomjs element.jsthe page title is Qucik Start | PhantomJS

    ?

    四. phantomjs與其他測(cè)試框剪的整合

    ? ??phantomjs本身不是一個(gè)測(cè)試框架,因此,需要借助其他的測(cè)試框剪來進(jìn)行測(cè)試運(yùn)行:常見的js測(cè)試框架已進(jìn)行運(yùn)行其列表如下:

    ? ??

    FrameworkTest Runner
    Buster.JSbuilt-in
    CapybaraPoltergeist,?Terminus
    MochaChutzpah,?mocha-phantomjs
    FuncUnitbuilt-in
    Hirobuilt-in
    Karma?(née Testacular)built-in
    JasmineChutzpah,?grunt-jasmine-runner,?guard-jasmine,?phantom-jasmine
    JsTestDriverjs-test-driver-phantomjs
    Laikabuilt-in
    Robot Frameworkphantomrobot
    QUnitbuilt-in,?Chutzpah,?JS Test Runner,?Qlive,?QUnited
    tapedeckbuilt-in
    Testembuilt-in
    WebDriverGhostDriver
    wrubuilt-in
    YUITestGrover,?phantomjs-yuitest

    ?

    以上參考http://phantomjs.org

    轉(zhuǎn)載于:https://www.cnblogs.com/dreamFromHere/p/3518296.html

    總結(jié)

    以上是生活随笔為你收集整理的phantomjs介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。