2014-11-05 58 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.