我使用以下腳本來獲取「chart_anchor」元素的outerHTML。phantomjs從chrome獲取不同的outerHTML檢查元素
var page = require('webpage').create();
var system = require('system'), address, myid;
if (system.args.length != 3)
{
console.log('Usage: ' + system.args[0] + ' <some URL> <ElementId>');
phantom.exit();
}
address = system.args[1];
myid = system.args[2];
page.open(address, function(status) {
console.log("Status: " + status + " " + address);
if(status === "success") {
var html = page.evaluate(function(elemid){
return document.getElementById(elemid).outerHTML; // "chart-section"
}, myid);
page.render('example.png');
console.log(html);
}
phantom.exit();
});
以下命令用於獲取節點的outerHTML,但輸出與chrome中的「Inspect Element」不同。有些專家可以幫助我獲得相同的結果嗎? 非常感謝。
./phantomjs l2.js 「http://www.google.com/finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=maximized&chdeh=0&chfdeh=0&chdet=1423200847674&chddm=1172.9999999999998&chls=IntervalBasedLine&q=NASDAQ%3AC&ntsp=0&fct=big&ei=TlLUVJnyAdDlqAG7r4H4Dg」 chart_anchor從phantomjs
<div id="chart_anchor" class="id-chart_anchor"><div id="image_chart"><table><tbody><tr><td class="itxt" align="left"><span class="linkbtn" onclick="_changeImage && _changeImage('1d',60, 1);">1d</span> <span class="linkbtn"
結果......更多
從鉻 <div id="chart_anchor" class="id-chart_anchor"><embed src="/finance/s/Med12Cbcdb8/chart9.swf?hl=en&gl=us" width="100%" height="340" type="application/x-shockwave-flash" menu="false" name="chartElement" id="chartElement" wmode="opaque" flashvars="lcId=142323
...更多
我還沒有成功,但以下鏈接似乎非常相關。 http://www.ryanbridges.org/2013/05/21/putting-the-flash-back-in-phantomjs/
有什麼區別?請更具體地瞭解您所得到的以及您的期望。您可以編輯您的問題以包含此信息。 – 2015-02-06 16:42:46
你想實現什麼?你是正確的,phantomjs沒有Flash支持。獲得相同結果的最簡單方法當然是在兩個瀏覽器中都獲得非閃存。 – 2015-02-07 06:52:01
我想獲得與Chrome的「檢查元素」功能相同的outerHTML。手動從瀏覽器複製它是一件痛苦的工作。現在我發現了一個phantomjs版本,它支持來自我的問題部分中的url的flash插件。 – flyaway 2015-02-07 07:00:24