js获取网页当中所有标签里面的文本
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>recursion</title>
<style type="text/css">
</style>
<script type="text/javascript">
var array = [];
onload = function ()
{
var tags = document.body.getElementsByTagName ('*');
for ( var i = 0; i < tags.length; i++)
{
array.push (getText (tags[i]));
}
console.log (array);
}
var getText = function (dom)
{
var index = 0, html = dom.innerHTML;
while (dom.children.length && index < dom.children.length)
{
var chtml = dom.children[index].outerHTML;
html = dom.innerHTML.replace(chtml, '');
index++;
}
return "<font>" + html + "</font>";
}
</script>
</head>
<body>
<p>
ths is p<a href="">this is a</a>wyz
</p>
<i>this is i</i>
<b>this is b</b>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |