如何从Nokogiri元素中获取元素?

时间:2015-07-29 11:06:58

标签: ruby-on-rails

这是我的rb文件:

    require "open-uri"
        require "nokogiri"


        url = "http://www.languagedaily.com/learn-german/vocabulary/common-german-words"
        html = open(url)
        doc = Nokogiri::HTML(html)

        row = doc.css("tr")
     row.each do |cell|
        puts cell
     end 

单独的元素如下所示:

   <tr class="rowA">
<td class="number">49.</td>
<td class="bigLetter">kann</td>
<td>(I) can, am able to (he/she/it) can (1st- and 3-rd person singular present of "können")</td>
<td>verb</td>
</tr>

我需要获得前三个td&#39。

1 个答案:

答案 0 :(得分:1)

继续使用css

row.css("td").take(3).each{}