1
私は次のHTMLを持つサイトhttp://www.example.com
からいくつかの情報こすりしよう:JSDOM:アクセスdivの内側のiframe
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My site</title>
</head>
<body>
<div id="one">
<div>
<iframe>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My site</title>
</head>
<body>
<div id="hello">
<a href="http://example.net/somepage"><img src="http://example.net/dokuro_chan.jpg"></a>
</div>
</body>
</html>
</iframe>
</div>
</div>
<div id="two">
<div>
<iframe>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My site</title>
</head>
<body>
<div id="hello">
<a href="http://example.net/somepage2"><img src="http://example.net/dokuro_chan2.jpg"></a>
</div>
</body>
</html>
</iframe>
</div>
</div>
</body>
</html>
をそれから私はjsdomを使用してnodejsを経由してiframeのコンテンツをこすりしよう:
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
JSDOM.fromURL("http://www.example.com",{
resources: "usable",
runScripts: "dangerously"
}).then(dom =>{
const divIds=["#one","#two"]
divIds.forEach((divId)=> {
const selector=googleAdSelector(divId)
const iframe=dom.window.document.querySelector(selector)
console.log("Iframe Object", iframe)
})
// callback(null,dom)
})
const googleAdSelector=function(divId){
return divId+" > div > iframe";
}
私が習得したいのは、href
とsrc
のコンテンツをiframeの中に入れることです。
しかし、出力が何らかの理由で
:iframeオブジェクトのヌル
iframeオブジェクトのヌル
あなたはINSIDE HTML はiframeにアクセスする方法を熱い任意のアイデアを持っていますか?