【问题标题】:Checking a checkbox with Mechanize使用机械化检查复选框
【发布时间】:2015-09-04 04:35:58
【问题描述】:

一旦我设法获得了我感兴趣的 NOKOGIRI 对象(在我的例子中是一个复选框),我该如何“检查”它? 我有以下内容

category.parent.children.children.check

返回这个充满 nokogiri 对象的数组:

 [#<Nokogiri::XML::Text:0x3fde5a78a26c "\r\n\t\t\t">, #<Nokogiri::XML::Element:0x3fde5a78a154 name="input" attributes=[#<Nokogiri::XML::Attr:0x3fde5a78a0a0 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x3fde5a78a064 name="name" value="epr_iid_selection[9]">, #<Nokogiri::XML::Attr:0x3fde5a78a014 name="value" value="652988">]>, #<Nokogiri::XML::Text:0x3fde4e0cd1b0 "\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t">, #<Nokogiri::XML::Text:0x3fde4e0cd0fc "Simple Messieurs Senior">, #<Nokogiri::XML::Text:0x3fde4e0ccfd0 "SM  ">, #<Nokogiri::XML::Text:0x3fde4e0cce2c "Senior">]

在这个数组中,我只对第二个元素感兴趣,这是一个我需要“检查”的复选框:

#<Nokogiri::XML::Element:0x3fde55a0a028 name="input" attributes=[#<Nokogiri::XML::Attr:0x3fde5a751f70 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x3fde5a751f48 name="name" value="epr_iid_selection[9]">, #<Nokogiri::XML::Attr:0x3fde5a751ef8 name="value" value="652988">]>

我该怎么做?

【问题讨论】:

    标签: ruby-on-rails web-scraping mechanize


    【解决方案1】:

    通常,您希望选中表单中的复选框。

    form.checkbox_with(:name => 'box').check
    

    有关更多信息,以下是相关文档:http://mechanize.rubyforge.org/GUIDE_rdoc.html

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2020-07-18
      • 1970-01-01
      相关资源
      最近更新 更多