使用javascript获取真实的源代码? [英] Getting real source code with javascript?

查看:46
本文介绍了使用javascript获取真实的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我对js的了解还不够多,但是有没有办法用它来获取页面的真实源代码?

OK I don't use js enough to know, but is there a way to get the real source code of the page with it?

document.body.innerHTML提供了某种修复"版本,其中已删除了格式错误的标记.

document.body.innerHTML for example gives some kind of "fixed up" version where malformed tags have been removed.

我猜想在原始页面上使用XMLHttpRequest可能有效,但似乎有点愚蠢.

I'm guessing using XMLHttpRequest on the original page might work, but seems kind of stupid.

推荐答案

之所以会发生这种情况,是因为浏览器会解析DOM,并且不会将HTML保留在内存中.返回给您的是浏览器将当前DOM转换回HTML的原因,这就是大写标签和缺乏适用的自闭标签的原因.

This happens because browsers parse the DOM and don't keep the HTML in memory. What is returned to you is the browser's conversion of the current DOM back to HTML, which is the reason for the uppercase tags and lack of self closing tags where applicable.

XMLHttpRequest将是最好的方法.在大多数情况下,假设服务器未发送no-cache标头,并且HTML页面已完成下载,则XMLHttpRequest几乎是即时的,因为文件是从缓存中获取的.

An XMLHttpRequest would be the best way to go. In most cases, assuming the server doesn't send the no-cache header, and the HTML page has finished downloading, the XMLHttpRequest would be almost instant because the file is fetched from the cache.

这篇关于使用javascript获取真实的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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