gpt4 book ai didi

javascript - 通过 PhantomJS 获取 Google Ads 内容

转载 作者:行者123 更新时间:2023-12-03 07:04:29 25 4
gpt4 key购买 nike

我想在网页上获取 Google Ads 内容。我正在使用 phantomJS,当我渲染图像时,我可以看到谷歌广告 block 。但是当我获取源代码(html)时,它只是 javascript 代码。

我的简单代码。

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();

};

渲染图像包含 Google 广告内容。

enter image description here

但是 HTML 源代码:

<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 -->

最佳答案

查看页面输出,似乎有一个名为“aswift_1”的 iframe。这又包含一个名为“google_ads_frame2”的 iframe。我不太熟悉Google广告的结构,但乍一看,这些看起来是用来输出广告内容的。

如果您想使用 phantomjs 获取此 iframe 内容,则可以使用如下代码:

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();
});

关于javascript - 通过 PhantomJS 获取 Google Ads 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com