2014-11-05 59 views
0

提前對不起,我的英語) 我有一個任務 - 爲網站編寫解析器,但他所有的頁面都將輸入的數據保存在HTML5本地存儲中。它真的模仿點擊頁面上的圖像,並檢索點擊後保存到數據存儲的所有變量值?例如,使用像jsdom這樣的NodeJS +解析器(https://github.com/tmpvar/jsdom)?或者我可以使用一些替代技術呢? 謝謝!如何解析使用HTML5本地存儲的頁面?

回答

0

聽起來就像你試圖解析一個網站有很多的JavaScript。您可以使用phontom來模擬用戶行爲。考慮你想使用節點。然後你可以使用Node-Phontom來做到這一點。

var phantom=require('node-phantom'); 
phantom.create(function(err,ph) { 
    return ph.createPage(function(err,page) { 
    return page.open("you/url/", function(err,status) { 
     console.log("opened site? ", status); 
     page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function(err) { 
     //jQuery Loaded. 
     //Settimeout to wait for a bit for AJAX call. 
     setTimeout(function() { 
      return page.evaluate(function() { 
      //Get what you want from the page 
      //e.g. localStorage.getItem('xxx'); 
     }, 5000); 
     }); 
    }); 
    }); 
}); 

Here is phontom.

Here is node-phontom.