如果您使用PhantomJS
http://phantomjs.org/
您可以简单地访问这些变量,就像您在网页中使用JavaScript一样。一个非常简单的例子如下:
//where url is the page that contains these variables.
page.open(url, function (status) {
//Page is loaded!
var dataFromPage = page.evaluate(function(){
return {
metrics_level2:metrics_level2,
metrics_level3:metrics_level3,
metrics_level4:metrics_level4
};
});
//dataFromPage now contains those variables
phantom.exit();
});
如果您已经将网页刮取并保存到html文件或其他文件中,则可以使用
content
方法相当于打开如上所述的页面。看见
http://phantomjs.org/api/webpage/property/content.html