如何通过JS获取网站实际的HTML代码? [英] How to get websites actual HTML code by JS?
问题描述
< input type ='text'value = name =dsa/>
他的价值为3;
他点击按钮保存。现在我想拥有网站的整个HTML,包括字段的值。所以我使用:
document.documentElement.innerHTML
但是我得到:
< input type ='text'value =name =dsa/>
但是我想得到这个:
< input type ='text'value =3name =dsa/>
注意我想把整个网站的HTML,不仅仅是一个字段。我不知道网站上会有哪些字段,所以我需要一个通用的解决方案。
AFAIK你不能从HTML代码,当用户在输入文本字段中输入内容时,HTML代码不会更改。
您可以做的是获取页面上的所有输入字段,获得他们的价值观如下:
var inputs,index;
inputs = document.getElementsByTagName('input'); (index = 0; index< inputs.length; ++ index)
{
//处理input [index]元素。
}
代码来自此帖子: https://stackoverflow.com/a/2214077/312312
我太懒了,把自己写下来:P
I have a website with a form. The form is filled by user with data for example i show to user:
<input type='text' value="" name="dsa" />
And he fills it with value of "3";
And he clicks button "save". Now i want to have the whole HTML of the website including values of fields. So i use:
document.documentElement.innerHTML
But i get:
<input type='text' value="" name="dsa" />
But i want to get this:
<input type='text' value="3" name="dsa" />
NOTICE I want to take the whole HTML of the website, not only one field. I dont know what fields will be on the website so i need a general solution.
AFAIK you can't get this from the HTML code, as the HTML code does not change when the user inputs something in a Input text field.
What you could do is get all input fields on the page and get their values with something like this:
var inputs, index;
inputs = document.getElementsByTagName('input');
for (index = 0; index < inputs.length; ++index) {
// deal with inputs[index] element.
}
The code is from this post: https://stackoverflow.com/a/2214077/312312 I was too lazy to write it down my self :P
这篇关于如何通过JS获取网站实际的HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!