让浏览器渲染HTML + JavaScript的 [英] get a browser rendered html+javascript

查看:209
本文介绍了让浏览器渲染HTML + JavaScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个comandline工具(或Javascript / PHP的,但我认为命令行是单程)的渲染,并得到URL的呈现的内容,但最重要的,我需要渲染器的Javascript不仅是CSS / HTML /图像。

I need a comandline tool (or Javascript/PHP, but i think commandline is the one way) for render and get the rendered content of URL, but the important its I need to renderer the Javascript not only the CSS/Html/images.

对于像示例命令:renderengine http://www.google.es outputfile.html和网页(解析HTML和JavaScript执行)ISA的内容保存在outputfile.html。

For example command like: "renderengine http://www.google.es outputfile.html" and the content of the web (parsed html and javascript executed) isa saved in outputfile.html.

我需要这个,因为我需要一个完整的JavaScript的网站一样的Grooveshark,网站加载所有使用JavaScript / AJAX和爬虫不发现什么都没有,只有基本的HTML空模板的结果(因为使用后AJAX / javscript加载)

I need this because i need to take the result of a full javascript website like grooveshark, the site load all using javascript/ajax and the crawlers dont find nothing, only basic HTML empty template (because is loaded after using ajax/javscript)

存在任何浏览器引擎用于为Javascript支持的Linux(例如V8),可输出的结果对于保存在文件?

Exists any browser engine for linux with support to Javascript (for example V8) that output the result for save in files?

推荐答案

尝试从 www.phantomjs.org phantomjs,你可以轻松地修改附带rasterize.js出口呈现的HTML。它基于WebKit和做你的目标网站的JavaScript的全面评估,让您调整超时或执行自己的code首先,如果你想。我个人用它来保存的完全呈现knockout.js模板印刷版的HTML文件版本。

Try phantomjs from www.phantomjs.org and you can easily modify the included rasterize.js to export the rendered HTML. It's based on webkit and does full evaluation of your target site's javascript, allowing you to adjust timeouts or execute your own code first if you wish. I personally use it to save hardcopy HTML file version of fully-rendered knockout.js templates.

据执行JavaScript,所以我只是做了这样的事情,并保存控制台输出到一个文件:

It executes javascript so I just did something like this and saved the console output to a file:

var markup = page.evaluate(function(){return document.documentElement.innerHTML;});
console.log(markup);
phantom.exit();

这篇关于让浏览器渲染HTML + JavaScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆