2016-04-27 7 views
0

Ich möchte Google-Anzeigeninhalte auf einer Webseite abrufen. Ich benutze phantomJS, wenn ich ein Bild rendere, kann ich Google Anzeigenblöcke sehen. Aber wenn ich Quelle (html) bekomme, ist es nur Javascript-Code.Get Google Ads content by PhantomJS

Mein einfacher Code.

var fs = require('fs'); 
var page = require('webpage').create(); 
var url = "http://www.thegeekstuff.com/2016/04/oracle-undo-tablespace/"; 

page.open(url); 

page.onLoadFinished = function() 
{ 

    fs.write("source.htm", page.content, 'w'); 
    page.render('render.png'); 
    phantom.exit(); 

}; 

Render Bild haben Google Anzeigen Inhalte.

enter image description here

Aber HTML Quelle:

<p>In the above example, we have two UNDO tablespace listed. But only one of them can be active and used by the system. The other one is currently not used.</p> 
<p>So, the best way to view the current valid UNDO tablespace is by using “show parameter” as shown below.</p> 
<center> 
    <div style="margin-left:2px; margin-top:10px; margin-bottom:10px; "> 

    <!-- AD BLOCK --> 

<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<!-- TGS Inside Content --> 
<ins class="adsbygoogle" style="display: inline-block; width: 300px; height: 250px;" data-ad-client="ca-pub-8090601437064582" data-ad-slot="8643685131" data-adsbygoogle-status="done"><ins id="aswift_1_expand" style="display:inline-table;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><ins id="aswift_1_anchor" style="display:block;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" 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){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;"></iframe></ins></ins></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

    <!-- END AD BLOCK --> 

Antwort

1

auf der Seite Ausgabe der Suche, es sieht ein iframe mit dem Namen 'aswift_1' sein. Dies wiederum enthält einen iframe namens "google_ads_frame2". Ich bin mir nicht mit der Struktur von Google-Anzeigen vertraut, aber auf einen Blick werden diese dazu verwendet, den Anzeigeninhalt auszugeben.

Wenn Sie diesen iframe Inhalte mit PhantomJS holen wollen, Code wie die folgenden funktionieren würde:

var fs = require('fs'); 
var page = require('webpage').create(); 
var url = "http://www.thegeekstuff.com/2016/04/oracle-undo-tablespace/"; 

page.open(url, function(status) { 
    if ('success' !== status) { 
     console.log("Error"); 
    } else { 
     page.switchToChildFrame('aswift_1'); 
     page.switchToChildFrame('google_ads_frame2'); 
     fs.write("test-google-source.htm", page.frameContent, 'w'); 
     page.render('test-google-render.png'); 
    } 
    phantom.exit(); 
}); 
+0

Ihnen sehr danken. – kju