Ruby / Rails - Scrapi宝石问题抓住下一个div文本

时间:2011-12-22 05:35:24

标签: html ruby-on-rails ruby

我有以下HTML:

<div class="tvShow" align="left">
    <div class="clearfix" style="margin:0px 0px;">
        <h3 class="left" style="margin:0px 0px">FIRST TUESDAY BOOK CLUB WITH JENNIFER BYRNE</h3>
    </div>

    <div>Thursday 22nd December at 2.00 pm (60 minutes)</div>

    <div><b>Channel: </b>ABC1</div>
    ...
</div>

我正在使用scrapi宝石来抓取内容。

这是我到目前为止提取h3

的内容
channel_item = Scraper.define do
    process "h3", :name => :text
end

# let scrapi begin

listings = Scraper.define do
    array :programs
    process "div.tvShow", :programs => channel_item
    result :programs
end

# loop through the listings

listings.scrape(uri).each do |program|
    puts program.name.titleize # h3 text
end

我不完全确定如何提取 12月22日星期四下午2点(60分钟)频道:ABC1 文字。

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个:

channel_item = Scraper.define do
  process "h3", :name => :text
  process "div[2]", :time => :text
  process "div[3]", :channel => :text
end

http://saxon.sourceforge.net/saxon6.5.3/expressions.html#NodeSetExpressions

希望这有帮助。