0

我尝试使用 jquery获取此页面( http://www.fotocommunity.de/fotograf/tu-fotodesign/fotos/794400 )的所有 URL。

当您滚动时,该站点将使用 AJAX 添加像素。这是我的脚本的一个片段:

for (i=0; i<100; i++) 
{
    var zahl=$('#thumbnails LI').eq(i).attr('id');
    var time=$('#thumbnails LI').eq(i).attr('data-time');
    console.log(i + ': ' + zahl+ ' ' + time);
}

我总是只得到前 12 个项目。任何想法,如何得到所有?我也尝试过mouseover或单击事件,但它始终只适用于前 12 个元素。

4

4 回答 4

3

您提供的网站使用“无尽”滚动效果。图像是从 XML 文件填充的。
在这里找到
您需要做的就是阅读源代码以找出答案。

于 2012-12-16T11:54:43.287 回答
2

jquery each() 是比 for 循环更好的选择

这个 jquery 片段将获取页面中的所有 href

var hrefs = $(document).find('a').map(function(){
    return this.href;
}).toArray();

您需要应用一些逻辑来仅获取照片href,但这应该可以帮助您入门

于 2012-12-16T12:08:09.693 回答
1

或者如果你想以超级有趣的方式来做!

var previous_scroll_top = 0;

var interval = setInterval(function(){
  $("body").scrollTop(3000000);

  // Don't do anything until we reach the bottom of the page!
  if (previous_scroll_top != $("body").scrollTop()) {
    previous_scroll_top = $("body").scrollTop();
    return true;
  } else {
    window.clearInterval(interval);
  }

  // Once we reach the bottom do this :)
  $('#thumbnails LI').each(function(index, el) {
    var zahl=$(el).attr('id');
    var time=$(el).attr('data-time');
    console.log(': ' + zahl+ ' ' + time);
  });
},1000);
于 2012-12-16T12:17:45.007 回答
0

您应该使用 jquery 的 each 循环遍历元素:http ://api.jquery.com/each/

于 2012-12-16T11:48:18.120 回答