PhantomJS - libraryPath 屬性



此屬性包含路徑,由 page.inectJs 方法使用。

語法

語法如下 −

var wpage = require('webpage').create(); 
wpage.libraryPath = 'filepath'; 

示例

看看下面的示例 −

var webPage = require('webpage'); 
var page = webPage.create();  
page.open('https://tutorialspoint.tw/jquery', function(status) { 
   if (status === "success") { 
      page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js ', function() { 
         if (page.injectJs('do.js')) { 
            var title = page.evaluate(function() { 
               // returnTitle is a function loaded from our do.js file - see below 
               return returnTitle(); 
            }); 
            console.log(title); 
            phantom.exit(); 
         } 
      }); 
   } 
}); 
window.returnTitle = function() { 
   return document.title; 
};

上述程式生成以下輸出。

Jquery Tutorial 
phantomjs_webpage_module_properties.htm
廣告
© . All rights reserved.