PhantomJS - libraryPath 属性



此属性包含路径,由 page.inectJs 方法使用。

语法

语法如下 −

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

示例

看看下面的示例 −

var webPage = require('webpage'); 
var page = webPage.create();  
page.open('https://tutorialspoint.com/jquery', function(status) { 
   if (status === "success") { 
      page.includeJs('https://ajax.googleapis.ac.cn/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.