Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 等待更多的帖子加载_Ruby On Rails_Ruby_Watir - Fatal编程技术网

Ruby on rails 等待更多的帖子加载

Ruby on rails 等待更多的帖子加载,ruby-on-rails,ruby,watir,Ruby On Rails,Ruby,Watir,我想要抓取的站点正在使用滚动事件进行延迟加载。无限滚动 我想等待加载更多的帖子,但所有帖子都有相同的类名。因此,我不能等待加载具有特定类名的元素。我不想用睡眠法 示例代码: <div class='posts'> <div class='single-post'></div> <div class='single-post'></div> <div class='single-post'></div> &

我想要抓取的站点正在使用滚动事件进行延迟加载。无限滚动 我想等待加载更多的帖子,但所有帖子都有相同的类名。因此,我不能等待加载具有特定类名的元素。我不想用睡眠法

示例代码:

<div class='posts'>
 <div class='single-post'></div>
 <div class='single-post'></div>
 <div class='single-post'></div>
 <div class='single-post'></div>
 // The following posts appear after scrolling. I want to fetch these posts
 <div class='single-post'></div>
 <div class='single-post'></div>
 <div class='single-post'></div>
 <div class='single-post'></div>
</div>
我如何解决这个问题?是否可以检查该部门的职位是否超过10个


想法?

您可以获得一组单个post div,以查看是否加载了更多。根据页面的标记,您可以执行以下操作:

browser.divs(class: 'single-post').count
或者,如果父母关系重大:

browser.div(class: 'posts').divs(class: 'single-post').count
这可用于等待职位数量增加:

# Find the original count
original_count = browser.divs(class: 'single-post').count

# Take an whatever action to trigger the loading of more posts
browser.scroll.to :bottom

# Wait for the count to increase
browser.wait_until do
  new_count = browser.divs(class: 'single-post').count
  new_count > original_count
end

谢谢你,干得好。。我还像这样解决了它:Watir::Wait.until{browser.divclass:'posts'.divindex:25.exist?}索引号达到you@Oğuzïiçek我喜欢你的方法,如果你走这条路,您可以通过以下方式轻松地用更少的代码完成此操作:browser.divclass:“posts”。dividex:25。等待&:exist?您可能会缩短到甚至browser.divclass:“single post”,index:25。等待&:exists?