0

多くの iframe からいくつかのリンク属性 (テキスト、href) を引き出そうとしています。

ソースコード:

<iframe width="120" height="600" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe>

ドキュメント内 (iframe)

<html>
  <head>
  <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/osd.js"></script>
  </head>
  <body marginwidth="0" marginheight="0">
     <iframe width="120" height="600" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" style="display:none" id="zrt_ads_frame1" name="zrt_ads_frame1" src="http://googleads.g.doubleclick.net/pagead/html/r20130628/r20130206/zrt_lookup.html">
     </iframe>
     <script>google_ad_client="pub-6276736854";google_ad_height=600;google_ad_slot="6197230xxx";google_ad_width=120;google_loader_used="sa";google_show_ads_impl=true;google_unique_id=1;google_async_iframe_id="aswift_0";google_ad_unit_key="212";google_start_time=1372933145673;google_ad_handling_experiment="PC";google_bpp=5;</script>
     <script src="http://pagead2.googlesyndication.com/pagead/js/r20130628/r20130206/show_ads_impl.js">
     </script>

     <script src="http://pagead2.googlesyndication.com/pagead/expansion_embed.js">
     </script>

     <script>google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);</script>

     <iframe allowtransparency="true" frameborder="0" height="600" hspace="0" id="google_ads_frame1" marginheight="0" marginwidth="0" name="google_ads_frame1" scrolling="no" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-627673xx&amp;output=html&amp;h=600&amp;slotname=6197230276&amp;w=120&amp;lmt=1372922345&amp;flash=11.7.700&amp;url=http%3A%2F%2Fahehl%2Falgeex.php&amp;dt=1372933145673&amp;bpp=5&amp;bdt=526&amp;shv=r20130628&amp;cbv=r20130206&amp;saldr=sa&amp;correlator=1372933145804&amp;frm=20&amp;adk=3222528636&amp;ga_vid=1998811959" style="left:0;position:absolute;top:0" vspace="0" width="120"></iframe>
   </body>
</html>

問題は、jQuery から 2 番目の iFrame にアクセスできないことです。

私はもう試した:

$(document).ready(function(){
    $('iframe').contents().find("html").html();
});

しかし、それは私にこれだけを出力します:

<iframe width="120" height="600" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" style="display:none" id="zrt_ads_frame1" name="zrt_ads_frame1" src="http://googleads.g.doubleclick.net/pagead/html/r20130628/r20130206/zrt_lookup.html"></iframe>

<script>google_ad_client="pub-6276736854";google_ad_height=600;google_ad_slot="6197230xxx";google_ad_width=120;google_loader_used="sa";google_show_ads_impl=true;google_unique_id=1;google_async_iframe_id="aswift_0";google_ad_unit_key="212";google_start_time=1372933145673;google_ad_handling_experiment="PC";google_bpp=5;</script>
<script src="http://pagead2.googlesyndication.com/pagead/js/r20130628/r20130206/show_ads_impl.js"></script>

すべてのデータを含む 2 番目の iframe がない場合。

私も試してみました find ('script').remove()。しかし、何もありません。

助言がありますか?

みんなありがとう。

4

1 に答える 1

0

なぜそれをしたいのかわからないが、:

  1. 他のドメインでホストされている iframe からコンテンツにアクセスすることはできません。詳細については、この関連する質問を参照してください。したがって、jQuery スニペットはブラウザー コンソールでのみ機能します (そのような制限はありません)。

  2. を使用して読み込み時にスクリプトを実行すると$(a_function)、iframe がまだ完全に読み込まれていない可能性があります (Google 広告は多くの非同期処理を行います)。したがって、取得するコンテンツは、関数実行時の実際のコンテンツです。

于 2013-08-22T06:49:19.817 に答える