使用Phantom.js评估,我怎么能获得页面的HTML? [英] Using Phantom.js evaluate, how can I get the HTML of the page?

查看:151
本文介绍了使用Phantom.js评估,我怎么能获得页面的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

page.evaluate(function() { return document; }, function(result){    
    console.log(result)                    
    next();
});

结果却是一个巨大的对象。我不知道该对象的属性和属性。我只是想在页面的HTML ,你会看到它在Chrome检查

从对象上来看,似乎包含HTML CSS和javascript..which是怪异。用户不应该看到CSS和JavaScript,因为它们不是网页的HTML。这些都是外部文件。我只希望,用户将看到的HTML。

From the look of the object, it seems that the HTML includes CSS and javascript..which is weird. The user should not see the CSS and javascript, because they are not the web page's HTML. Those are external files. I only want the HTML that the user would see.

推荐答案

类型文件是一个HTML文档。为了让整个DOM作为一个字符串,你可以做 document.documentElement.outerHTML

The type of document is an HTML document. To get the entire DOM as a string, you could do document.documentElement.outerHTML.

从外评估,您可以使用 page.content 。这是一个字符串。

From outside evaluate, you can use page.content. It is a string.

我不知道你的意思是HTML,包括CSS和JavaScript或网页的HTML。你指的是页面的源代码和DOM之间的差别通过脚本​​为修改?上述两个给你当前的DOM,而不是原始网页的源文件。

I don't know what you mean by "HTML includes CSS and JavaScript" or "the web page's HTML". Are you referring to the difference between the page source and the DOM as modified by scripting? Both the above give you the current DOM, not the original page source.

这篇关于使用Phantom.js评估,我怎么能获得页面的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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