コード化された次のページがあります。
mypage.html:
<html><script>var a=document.createElement('p');
a.innerHTML="hello world";
document.body.appendChild(a);</script>
<body>
<p>testing 1 2 3....</p></body>
</html>
次のコードを持つfind.htmlで情報を取得すると。
<script>
window.onload =finder();
function finder(){
var iframe=document.createElement('iframe');
iframe.width=1;
iframe.height=1;
iframe.src='mypage.html';
iframe.setAttribute('id', 'iframer');
document.body.appendChild(iframe);
setTimeout(
function() {
var e = document.getElementById("iframer");
var frameHTML = e.contentDocument; var serializer = new XMLSerializer(); var content = serializer.serializeToString(frameHTML); alert(content);
} , 30000);
}
</script>
最終結果は、アラート ポップアップのように表示されます。
<html><script>var a=document.createElement('p');
a.innerHTML="hello world";
document.body.appendChild(a);</script>
<body>
<p>testing 1 2 3....</p></body>
</html>
それは私が探しているものではありません。ブラウザでレンダリングされた次のようなコンテンツを取得しようとしています。すべてのレンダリングおよび生成された動的ソース コードを検査用にのみ取得する必要があります。レンダリングされた HTML ソース コードを取得するにはどうすればよいですか。
<body>
<p>hello world</p>
<p>testing 1 2 3....</p>
</body>