如何从页面获取HTML源代码? [英] How do I get the HTML source from the page?

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

问题描述



我知道我可以使用 document.body.innerHTML

有没有办法使用javascript访问页面的HTML源代码? / code>但它只包含正文中的代码。我想要获取所有的页面源代码,包括头部和身体标签以及它们的内容,如果可能的话,还需要html标签和文档类型。
是否可能?

解决方案

使用

  document.documentElement.outerHTML 

  document.documentElement.innerHTML 


Is there a way to access the page HTML source code using javascript?

I know that I can use document.body.innerHTML but it contains only the code inside the body. I want to get all the page source code including head and body tags with their content, and, if it's possible, also the html tag and the doctype. Is it possible?

解决方案

Use

document.documentElement.outerHTML

or

document.documentElement.innerHTML

这篇关于如何从页面获取HTML源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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