javascript读取广告名称

发布于 2024-10-14 11:30:18 字数 8245 浏览 7 评论 0原文

问题 在 Adsence 上,他们不会告诉您哪些广告正在展示,哪些广告没有展示,因为很多广告我不希望它们展示,因为它包含一些内容,这违反了我们的社区政策,例如比基尼女孩或维格拉广告或许多其他广告。

解决方案思路 我想知道是否可以通过 javascript 读取我的网站上显示的 Adsense 广告。我问的原因是他们使用 iframe 来投放广告。我想做的就是阅读那里显示的广告并记录下来。如果我需要阻止或不需要阻止数千个广告,我可以稍后查看它。我什至可能只是放置报告广告链接,它将自动显示当前广告的名称。

小示例代码

  var iframeID = jQuery('iframe').attr('id');           

        console.log(document.getElementById(iframeID).contentWindow.document.body.innerHTML);

    output:
    <script>(function(){window.ss=function(d,e){window.status=d;var c=document.getElementById(e);if(c){var a;a=c.href;var b=a.match("^(.*)([?|&]nm=)([^&]*)(.*)$");if(b){b[3]=(Number(b[3])||0)+1;b[0]="";a=b.join("")}else a=a+"&nm=1";c.href=a}return true};})();function su(id) {var a = document.getElementById(id);var b = (new Date()).getTime();if (a && a.myt && b) {var t = b - a.myt;var bi = a.href.indexOf("&clkt=");if (bi > 0) {var c = a.href.substring(0, bi+6); var d = a.href.substring(bi+6, a.href.length);var ei = d.indexOf("&");var r = '';if (ei >= 0)r = d.substring(ei, d.length);a.href = c + t + r; } else {a.href += "&clkt=" + t;}}return true;}function cs(){window.status='';} function jcc(a) {pha=document.getElementById(a); nc=pha.href.indexOf('&jca='); if(nc>=1) return; jca=(401)+(344)-(324); if (a=='aw0') {jca+=(6844);} else {jca=0;} phb=pha.href+'&jca='+jca; pha.href=phb;} function st(id) {var a = document.getElementById(id);if (a) {a.myt = (new Date()).getTime();}return true;}function ha(a){  var pha=document.getElementById(a);var nhi=pha.href.indexOf("&nh=");if(nhi < 1) {pha.href+="&nh=1";}su(a); jcc(a); }function ca(a) {  var pha=document.getElementById(a);var nci=pha.href.indexOf("&nc=");if(nci < 1) {pha.href+="&nc=1";}su(a); jcc(a); top.location.href=document.getElementById(a).href;}function ga(o,e) {if (document.getElementById) {a=o.id.substring(1);p="";r="";g=e.target;if (g) {t=g.id;f=g.parentNode;if (f) {p=f.id;h=f.parentNode;if (h)r=h.id;}} else {h=e.srcElement;f=h.parentNode;if (f)p=f.id;t=h.id;}if (t==a||p==a||r==a)return true;var pha=document.getElementById(a);var nbi=pha.href.indexOf("&nb=");if(nbi < 1) {pha.href+="&nb=1";}su(a); jcc(a); top.location.href=document.getElementById(a).href;}}</script><script>document.close();</script>

当我在控制台中预览 iframe 代码时,上面的代码位于标题中,正文中包含所有广告

following is the iframe code which i preview in console:
<html>
<head>
<style>
a:link,a:visited,a:hover,a:active {
    color: #0000ff;
    cursor: pointer;
}

body,table,div,ul,li {
    font-size: 10px;
    margin: 0px;
    padding: 0px
}

body {
    background-color: transparent;
    font-family: verdana, arial, sans-serif;
    height: 100%
}

#aus {
    height: 250px;
    width: 300px
}

#ads {
    left: 0px;
    position: absolute;
    top: 0px;
    width: 300px
}

#ads ul {
    list-style: none;
}

#ads ul li {
    clear: both;
    float: left;
    height: 232px;
    margin: 0px 21px 0px 21px;
    overflow: hidden;
    width: 258px
}

.ad {
    margin: 0px 0px
}

.adt {
    font-size: 13px;
    font-weight: bold;
}

.adb {
    color: #000000;
    display: block;
    font-size: 13px;
}

.adu {
    color: #009900;
    font-size: 10px;
    line-height: 12px;
    overflow: hidden;
    white-space: nowrap
}

.adus {
    cursor: pointer;
}

.adc {
    height: 232px;
    overflow: hidden;
    table-layout: fixed;
    width: 100%
}

#ainw {
    left: 3px;
    position: absolute;
    top: 235px
}

#abgi {
    left: 202px;
    position: absolute;
    top: 233px
}

#aubg {
    background-color: #ffffff;
    border: 0px solid #ffffff;
    height: 250px;
    width: 300px
}
</style>
<script>(function(){window.ss=function(d,e){window.status=d;var c=document.getElementById(e);if(c){var a;a=c.href;var b=a.match("^(.*)([?|&amp;]nm=)([^&amp;]*)(.*)$");if(b){b[3]=(Number(b[3])||0)+1;b[0]="";a=b.join("")}else a=a+"&amp;nm=1";c.href=a}return true};})();function su(id) {var a = document.getElementById(id);var b = (new Date()).getTime();if (a &amp;&amp; a.myt &amp;&amp; b) {var t = b - a.myt;var bi = a.href.indexOf("&amp;clkt=");if (bi &gt; 0) {var c = a.href.substring(0, bi+6); var d = a.href.substring(bi+6, a.href.length);var ei = d.indexOf("&amp;");var r = '';if (ei &gt;= 0)r = d.substring(ei, d.length);a.href = c + t + r; } else {a.href += "&amp;clkt=" + t;}}return true;}function cs(){window.status='';} function jcc(a) {pha=document.getElementById(a); nc=pha.href.indexOf('&amp;jca='); if(nc&gt;=1) return; sv=String.fromCharCode(49,49,51,56,57,55,49,56,51); sv=sv.slice(0,4); jca=(4446)+parseInt(sv); if (a=='aw0') {jca+=(-929);} else {jca=0;} phb=pha.href+'&amp;jca='+jca; pha.href=phb;} function st(id) {var a = document.getElementById(id);if (a) {a.myt = (new Date()).getTime();}return true;}function ha(a){  var pha=document.getElementById(a);var nhi=pha.href.indexOf("&amp;nh=");if(nhi &lt; 1) {pha.href+="&amp;nh=1";}su(a); jcc(a); }function ca(a) {  var pha=document.getElementById(a);var nci=pha.href.indexOf("&amp;nc=");if(nci &lt; 1) {pha.href+="&amp;nc=1";}su(a); jcc(a); window.open(document.getElementById(a).href);}function ga(o,e) {if (document.getElementById) {a=o.id.substring(1);p="";r="";g=e.target;if (g) {t=g.id;f=g.parentNode;if (f) {p=f.id;h=f.parentNode;if (h)r=h.id;}} else {h=e.srcElement;f=h.parentNode;if (f)p=f.id;t=h.id;}if (t==a||p==a||r==a)return true;var pha=document.getElementById(a);var nbi=pha.href.indexOf("&amp;nb=");if(nbi &lt; 1) {pha.href+="&amp;nb=1";}su(a); jcc(a); window.open(document.getElementById(a).href);}}</script>
</head>
<body>
<div id="aus">
<div id="aubg"></div>
<div id="ads">
<ul id="ads0">
    <li onmouseover="ss('','aw0')" onfocus="ss('','aw0')" id="taw0">
    <div class="ad">
    <table cellspacing="0" cellpadding="0" border="0" class="adc">
        <tbody>
            <tr>
                <td valign="middle"><a target="_blank"
                    onmouseover="return ss('','aw0')" onmousedown="st('aw0')"
                    onfocus="ss('','aw0')" onclick="ha('aw0')" id="aw0"
                    href="http://googleads.g.doubleclick.net/aclk?sa=L&amp;ai=ByWWG079CTeSRJI2MsgaAx93rBaCluFLmxLGnBsCNtwHAqQcQARgBIL39zQo4AFDVluesBWDL9LQFsgEQYmFzaXQuaXJlc2FsYS5pbboBCjMwMHgyNTBfYXPIAQHaASNodHRwOi8vYmFzaXQuaXJlc2FsYS5pbS9wUDJFU3NBYUpocuABAqkCigtjQVkTpT7gAgDqAhtzb2NpYWxfbWVkaWFfZGV0YWlsXzMwMHgyNTCQA_wHmAOkA6gDAcgDF-gDhAf1AwAAAMTgBAE&amp;num=1&amp;sig=AGiWqty6HglfRNFl5bjFjEG438XjgFQw3w&amp;client=ca-pub-&amp;adurl=http://www.gepaelk.com"
                    class="adt"><span>Reaktif Güç Kont. Rölesi</span></a>
                <div class="adb">Kompanzasyonda kesin çözüm. Klasik ve
                Thiristörlü çözümler.</div>
                <div class="adu"><span onmousedown="st(this.id.substr(1))"
                    onclick="ga(this,event)" id="uaw0" class="adus">www.gepaelk.com</span></div>
                </td>
            </tr>
        </tbody>
    </table>
    </div>
    </li>
</ul>
</div>
<img width="11" height="11"
    src="http://pagead2.googlesyndication.com/pagead/images/ainw_000000.gif"
    id="ainw" alt="">
<div id="abgi"><a target="_blank"
    href="http://www.google.com/url?ct=abg&amp;q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://basit.iresala.im/pP2ESsAaJhr%26hl%3Dtr%26client%3Dca-pub-%26adU%3Dwww.gepaelk.com%26adT%3DReaktif%2BG%25C3%25BC%25C3%25A7%2BKont.%2BR%25C3%25B6lesi%26gl%3DPK&amp;usg=AFQjCNGXuz2ZcyVIMFSpO3el2DEDVHZQkw"><img
    width="96" height="16" border="0"
    src="http://pagead2.googlesyndication.com/pagead/abglogo/abg-tr-100c-000000.png"
    alt="Google Reklamları"></a></div>
</div>
<script>document.close();</script>
</body>
</html>

因此请提供任何想法/解决方案。

Problem
on adsence they dont tell you which ads are showing and which not, because lots of ads i dont want them to show, because it has some content, which goes against our community policy, like bikini girls or vigra ads or many others.

Solution Idea
i wanted to know if its possible to read what adsense ads showing on my website through javascript. well the reason i asked, is because they are using iframe for ads. all i want to do, is read there showing ads and log it. which i can later review it, if i need to block thous ads or no. i might even just put report ads link, which will auto names of the current ads showing.

Little Sample Code

  var iframeID = jQuery('iframe').attr('id');           

        console.log(document.getElementById(iframeID).contentWindow.document.body.innerHTML);

    output:
    <script>(function(){window.ss=function(d,e){window.status=d;var c=document.getElementById(e);if(c){var a;a=c.href;var b=a.match("^(.*)([?|&]nm=)([^&]*)(.*)$");if(b){b[3]=(Number(b[3])||0)+1;b[0]="";a=b.join("")}else a=a+"&nm=1";c.href=a}return true};})();function su(id) {var a = document.getElementById(id);var b = (new Date()).getTime();if (a && a.myt && b) {var t = b - a.myt;var bi = a.href.indexOf("&clkt=");if (bi > 0) {var c = a.href.substring(0, bi+6); var d = a.href.substring(bi+6, a.href.length);var ei = d.indexOf("&");var r = '';if (ei >= 0)r = d.substring(ei, d.length);a.href = c + t + r; } else {a.href += "&clkt=" + t;}}return true;}function cs(){window.status='';} function jcc(a) {pha=document.getElementById(a); nc=pha.href.indexOf('&jca='); if(nc>=1) return; jca=(401)+(344)-(324); if (a=='aw0') {jca+=(6844);} else {jca=0;} phb=pha.href+'&jca='+jca; pha.href=phb;} function st(id) {var a = document.getElementById(id);if (a) {a.myt = (new Date()).getTime();}return true;}function ha(a){  var pha=document.getElementById(a);var nhi=pha.href.indexOf("&nh=");if(nhi < 1) {pha.href+="&nh=1";}su(a); jcc(a); }function ca(a) {  var pha=document.getElementById(a);var nci=pha.href.indexOf("&nc=");if(nci < 1) {pha.href+="&nc=1";}su(a); jcc(a); top.location.href=document.getElementById(a).href;}function ga(o,e) {if (document.getElementById) {a=o.id.substring(1);p="";r="";g=e.target;if (g) {t=g.id;f=g.parentNode;if (f) {p=f.id;h=f.parentNode;if (h)r=h.id;}} else {h=e.srcElement;f=h.parentNode;if (f)p=f.id;t=h.id;}if (t==a||p==a||r==a)return true;var pha=document.getElementById(a);var nbi=pha.href.indexOf("&nb=");if(nbi < 1) {pha.href+="&nb=1";}su(a); jcc(a); top.location.href=document.getElementById(a).href;}}</script><script>document.close();</script>

when i preview the iframe code in console, then this above code is in the header and body has all the ads

following is the iframe code which i preview in console:
<html>
<head>
<style>
a:link,a:visited,a:hover,a:active {
    color: #0000ff;
    cursor: pointer;
}

body,table,div,ul,li {
    font-size: 10px;
    margin: 0px;
    padding: 0px
}

body {
    background-color: transparent;
    font-family: verdana, arial, sans-serif;
    height: 100%
}

#aus {
    height: 250px;
    width: 300px
}

#ads {
    left: 0px;
    position: absolute;
    top: 0px;
    width: 300px
}

#ads ul {
    list-style: none;
}

#ads ul li {
    clear: both;
    float: left;
    height: 232px;
    margin: 0px 21px 0px 21px;
    overflow: hidden;
    width: 258px
}

.ad {
    margin: 0px 0px
}

.adt {
    font-size: 13px;
    font-weight: bold;
}

.adb {
    color: #000000;
    display: block;
    font-size: 13px;
}

.adu {
    color: #009900;
    font-size: 10px;
    line-height: 12px;
    overflow: hidden;
    white-space: nowrap
}

.adus {
    cursor: pointer;
}

.adc {
    height: 232px;
    overflow: hidden;
    table-layout: fixed;
    width: 100%
}

#ainw {
    left: 3px;
    position: absolute;
    top: 235px
}

#abgi {
    left: 202px;
    position: absolute;
    top: 233px
}

#aubg {
    background-color: #ffffff;
    border: 0px solid #ffffff;
    height: 250px;
    width: 300px
}
</style>
<script>(function(){window.ss=function(d,e){window.status=d;var c=document.getElementById(e);if(c){var a;a=c.href;var b=a.match("^(.*)([?|&]nm=)([^&]*)(.*)$");if(b){b[3]=(Number(b[3])||0)+1;b[0]="";a=b.join("")}else a=a+"&nm=1";c.href=a}return true};})();function su(id) {var a = document.getElementById(id);var b = (new Date()).getTime();if (a && a.myt && b) {var t = b - a.myt;var bi = a.href.indexOf("&clkt=");if (bi > 0) {var c = a.href.substring(0, bi+6); var d = a.href.substring(bi+6, a.href.length);var ei = d.indexOf("&");var r = '';if (ei >= 0)r = d.substring(ei, d.length);a.href = c + t + r; } else {a.href += "&clkt=" + t;}}return true;}function cs(){window.status='';} function jcc(a) {pha=document.getElementById(a); nc=pha.href.indexOf('&jca='); if(nc>=1) return; sv=String.fromCharCode(49,49,51,56,57,55,49,56,51); sv=sv.slice(0,4); jca=(4446)+parseInt(sv); if (a=='aw0') {jca+=(-929);} else {jca=0;} phb=pha.href+'&jca='+jca; pha.href=phb;} function st(id) {var a = document.getElementById(id);if (a) {a.myt = (new Date()).getTime();}return true;}function ha(a){  var pha=document.getElementById(a);var nhi=pha.href.indexOf("&nh=");if(nhi < 1) {pha.href+="&nh=1";}su(a); jcc(a); }function ca(a) {  var pha=document.getElementById(a);var nci=pha.href.indexOf("&nc=");if(nci < 1) {pha.href+="&nc=1";}su(a); jcc(a); window.open(document.getElementById(a).href);}function ga(o,e) {if (document.getElementById) {a=o.id.substring(1);p="";r="";g=e.target;if (g) {t=g.id;f=g.parentNode;if (f) {p=f.id;h=f.parentNode;if (h)r=h.id;}} else {h=e.srcElement;f=h.parentNode;if (f)p=f.id;t=h.id;}if (t==a||p==a||r==a)return true;var pha=document.getElementById(a);var nbi=pha.href.indexOf("&nb=");if(nbi < 1) {pha.href+="&nb=1";}su(a); jcc(a); window.open(document.getElementById(a).href);}}</script>
</head>
<body>
<div id="aus">
<div id="aubg"></div>
<div id="ads">
<ul id="ads0">
    <li onmouseover="ss('','aw0')" onfocus="ss('','aw0')" id="taw0">
    <div class="ad">
    <table cellspacing="0" cellpadding="0" border="0" class="adc">
        <tbody>
            <tr>
                <td valign="middle"><a target="_blank"
                    onmouseover="return ss('','aw0')" onmousedown="st('aw0')"
                    onfocus="ss('','aw0')" onclick="ha('aw0')" id="aw0"
                    href="http://googleads.g.doubleclick.net/aclk?sa=L&ai=ByWWG079CTeSRJI2MsgaAx93rBaCluFLmxLGnBsCNtwHAqQcQARgBIL39zQo4AFDVluesBWDL9LQFsgEQYmFzaXQuaXJlc2FsYS5pbboBCjMwMHgyNTBfYXPIAQHaASNodHRwOi8vYmFzaXQuaXJlc2FsYS5pbS9wUDJFU3NBYUpocuABAqkCigtjQVkTpT7gAgDqAhtzb2NpYWxfbWVkaWFfZGV0YWlsXzMwMHgyNTCQA_wHmAOkA6gDAcgDF-gDhAf1AwAAAMTgBAE&num=1&sig=AGiWqty6HglfRNFl5bjFjEG438XjgFQw3w&client=ca-pub-&adurl=http://www.gepaelk.com"
                    class="adt"><span>Reaktif Güç Kont. Rölesi</span></a>
                <div class="adb">Kompanzasyonda kesin çözüm. Klasik ve
                Thiristörlü çözümler.</div>
                <div class="adu"><span onmousedown="st(this.id.substr(1))"
                    onclick="ga(this,event)" id="uaw0" class="adus">www.gepaelk.com</span></div>
                </td>
            </tr>
        </tbody>
    </table>
    </div>
    </li>
</ul>
</div>
<img width="11" height="11"
    src="http://pagead2.googlesyndication.com/pagead/images/ainw_000000.gif"
    id="ainw" alt="">
<div id="abgi"><a target="_blank"
    href="http://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://basit.iresala.im/pP2ESsAaJhr%26hl%3Dtr%26client%3Dca-pub-%26adU%3Dwww.gepaelk.com%26adT%3DReaktif%2BG%25C3%25BC%25C3%25A7%2BKont.%2BR%25C3%25B6lesi%26gl%3DPK&usg=AFQjCNGXuz2ZcyVIMFSpO3el2DEDVHZQkw"><img
    width="96" height="16" border="0"
    src="http://pagead2.googlesyndication.com/pagead/abglogo/abg-tr-100c-000000.png"
    alt="Google Reklamları"></a></div>
</div>
<script>document.close();</script>
</body>
</html>

so any ideas/solution please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜你已久 2024-10-21 11:30:18

无论您的意图有多好,单源政策都会阻止对广告的任何访问。在页面内使用纯 JavaScript 是没有办法解决这个问题的。

但是,您可以使用专用计算机、浏览器和自动化解决方案(例如 Selenium)进行设置来记录显示的广告。不过,我预计实施起来会相当困难。

No matter how good your intentions, the Single Origin Policy will block any access to the ad. There is no way around it using pure JavaScript inside the page.

You might, however, be able to set something up using a dedicated computer, a browser and a automation solution like Selenium to record displayed ads. I expect it's going to be rather tough to implement, though.

江湖彼岸 2024-10-21 11:30:18

很简单

        console.log(jQuery('iframe').contents().find('#ads0').html());

its simple

        console.log(jQuery('iframe').contents().find('#ads0').html());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文