【问题标题】:get the second element with mechanize用机械化获得第二个元素
【发布时间】:2015-01-28 16:56:01
【问题描述】:

当我执行下面的代码时,我会在输出中得到这个

适合法国

适合意大利人

但我需要链接的第二个元素,我怎样才能得到它? 当我只执行 a.get("http://............links_with(:href => %r{/suits-}) 一切都很好时,我什么都不懂

 0.upto(5) do |f|
   p = a.get("http://www.xxxx/recherche/#{name}/page-#{f}").links_with(:href => %r{/suits-})
   puts p
end 

Mechanize::Page::Link "Suits FRENCH " "http://www.xxxxxx/rent/r-s-t/suits-french.html"> ,

Mechanize::Page::Link "Suits ITALIEN" "http://www.xxxxx/rent/r-s-t/suits-italien.html">*

【问题讨论】:

    标签: ruby mechanize


    【解决方案1】:

    应该是这样的:

    links = a.get("http://www.xxxx/recherche/#{name}/page-#{f}").links_with(:href => %r{/suits-})
    link = links[1]
    

    0 是第一个,1 是第二个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      相关资源
      最近更新 更多