2015-11-08 45 views
0

我写上casperjs/phantomjs一些刮脚本,并试图从goodle广告的iframe代码的一个HTML内容和获取错误获取HTML代码的iframe - “无法读取contentDocument”错误

代码:

iframe_node = $('iframe').contents().find('iframe[name^="google_ads_frame"]')[0] 
html = a.contentDocument.body.innerHTML 

错误:

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': 
Blocked a frame with origin "http://example.com" from accessing a cross-origin frame.(…) 
+1

您可以将CasperJS的上下文从[this](http://stackoverflow.com/a/14154214/1816580)更改为iframe的内容,并从casper.getHTML() –

回答

0

尝试改变以下变量,网络安全,SSL的错误,和SSL协议:

casperjs --web-security=false --ignore-ssl-errors=true --ssl-protocol=any <your_script>.js 

由于安全设置的原因,您无法调整这些变量而无法访问跨源帧。这应该允许您输入框架并获取必要的内容。