我需要从网页中提取所有文本内容。我已经使用了“document.body.textContent”的方法,但是我也获得了JavaScript内容。如何确保我只获取可读的文本内容?
function myFunction() {
var str = document.body.textContent
alert(str);
}
<html>
<title>Test Page for Text extraction</title>
<head>I hope this works</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<body>
<p>Test on this content to change the 5th word to a link
<p>
<button onclick="myFunction()">Try it</button>
</body>
</hmtl>