Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 Watir webdriver未抓取指定的div,不确定原因?_Ruby On Rails_Ruby_Phantomjs_Watir Webdriver - Fatal编程技术网

Ruby on rails Watir webdriver未抓取指定的div,不确定原因?

Ruby on rails Watir webdriver未抓取指定的div,不确定原因?,ruby-on-rails,ruby,phantomjs,watir-webdriver,Ruby On Rails,Ruby,Phantomjs,Watir Webdriver,这是控制器的代码,我正在尝试使用 class ScraperController < ApplicationController def getinformation require 'watir-webdriver' require 'phantomjs' @browser = Watir::Browser.new:phantomjs @browser.goto "http://reddit.com" @divs = @

这是控制器的代码,我正在尝试使用

class ScraperController < ApplicationController

  def getinformation
      require 'watir-webdriver'
      require 'phantomjs'

      @browser = Watir::Browser.new:phantomjs
      @browser.goto "http://reddit.com"
      @divs = @browser.divs(class: "title may-blank ")

  end

end
class ScraperController
在查看页面上,我有,它输出0。当我在浏览页面上输入时,它会给我“reddit:互联网的首页”,所以我知道我从网页上得到了一些东西


通过查看主页上一些帖子的标题,我发现了div类“title may blank”,并且我尝试了使用div类“title may blank”和“title may blank”。一个在末尾有空格,在reddit页面上检查时如何显示,另一个在末尾没有空格。但他们都没给我什么

假设您正在尝试查找:

<a class="title may-blank outbound" data-event-action="title" href="https://i.redd.it/kxtpiskh9mez.jpg" tabindex="1" data-href-url="https://i.redd.it/kxtpiskh9mez.jpg" data-outbound-url="https://out.reddit.com/t3_6si8wj?url=https%3A%2F%2Fi.redd.it%2Fkxtpiskh9mez.jpg&amp;token=AQAAKQiLWXNK30ZkH9-TplVYPCVEIJwNWgqFZCdFuOc3O5l1c7M1&amp;app_name=reddit.com" data-outbound-expiration="1502283817000" rel="">Fries</a>
虽然这将返回结果,但它可能不是您所期望的一切。Watir中也不赞成在
字符串中支持多个类

我想你实际上只想:

@browser.links(class: "title")
如果两个类都需要,请使用:

@browser.links(class: ["title", "may-blank"])

假设您正在尝试查找:

<a class="title may-blank outbound" data-event-action="title" href="https://i.redd.it/kxtpiskh9mez.jpg" tabindex="1" data-href-url="https://i.redd.it/kxtpiskh9mez.jpg" data-outbound-url="https://out.reddit.com/t3_6si8wj?url=https%3A%2F%2Fi.redd.it%2Fkxtpiskh9mez.jpg&amp;token=AQAAKQiLWXNK30ZkH9-TplVYPCVEIJwNWgqFZCdFuOc3O5l1c7M1&amp;app_name=reddit.com" data-outbound-expiration="1502283817000" rel="">Fries</a>
虽然这将返回结果,但它可能不是您所期望的一切。Watir中也不赞成在
字符串中支持多个类

我想你实际上只想:

@browser.links(class: "title")
如果两个类都需要,请使用:

@browser.links(class: ["title", "may-blank"])

您应该切换到“Watir”而不是“Watir Webdriver”。Watir Webdriver代码库已弃用。它的更新现在发生在瓦蒂尔。谢谢你的建议!可以。你应该切换到“Watir”而不是“Watir Webdriver”。Watir Webdriver代码库已弃用。它的更新现在发生在瓦蒂尔。谢谢你的建议!好的。非常感谢你!!在发布stackoverflow之前,我曾尝试查看Watir文档,试图解决我的问题,但似乎在那里找不到我的答案。我只是需要更仔细地看看,还是你知道有一本关于瓦蒂尔的好教程?你可以试试我的书。这本书只写了一部分,有点过时,但它是一个起点。非常感谢!!在发布stackoverflow之前,我曾尝试查看Watir文档,试图解决我的问题,但似乎在那里找不到我的答案。我只是需要更仔细地看看,还是你知道有一本关于瓦蒂尔的好教程?你可以试试我的书。这本书只写了一部分,有点过时,但它是一个起点。