1

我正在抓取一些网站,我想去掉页面上的 Adob​​e Flash 广告。我认为它们是“对象”,所以我做了:

window.setInterval(MyFunction, 900);

function MyFunction() { 

  $('object').remove();

alert('test'); 

} 

我看到了警报,但没有删除“对象”。这怎么可能?我还能尝试什么?

这是(其中一个)广告的外观:

<script src="http://ad.nl.doubleclick.net/adj/P4442.Nu.nl/home;sz=468x60,728x90;dcopt=ist;tile=1;kw=;tt=1000;gr=-5;rg=0;nk=0;u=m6re350ar;;ord=4884951752610505?" type="text/javascript" style="position: relative; margin: 0px; padding: 0px; width: auto; height: auto; border: none; float: left; background-image: none; background-position: initial initial; background-repeat: initial initial;"></script>
4

2 回答 2

1

您的 Flash 广告可能使用<embed>元素而不是<object>. 例如,我只是尝试加载http://www.drudgereport.com/几次,并在不同时间找到了这两种元素类型。$('object').length您可以通过记录和找出哪些存在$('embed').length。要删除它们,您可以使用:

$('embed,object').length

因此,在您的函数中添加了一些日志记录代码:

function MyFunction() {
    console.log( 'Objects:', $('object').length );
    console.log( 'Embeds:', $('embed').length );
    $('embed,object').remove();
    console.log( 'Objects after:', $('object').length );
    console.log( 'Embeds after:', $('embed').length );
}

您的 0.9 秒超时也可能不够。运行代码并稍等片刻后,您可以console.log()再次尝试这些调用,看看结果如何。

于 2013-03-23T09:41:14.790 回答
0
setTimeout(function() {
    $('object').remove();  
}, 900);
于 2013-03-23T09:24:14.837 回答