Q:

Parsing links from a table using Nokogiri

This is what I'm trying to do: 

Look for a span tag with a particular inner text. 
Get the table that follows this span tag. 
Retrieve all the href links inside this table. 

For example, I've taken the source of a Wiki page: 
<h2><span class="mw-headline" id="Filmography">Filmography</span><span class="mw-editsection">           <span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Katie_Holmes&amp;action=edit&amp;section=10" title="Edit section: Filmography">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<table class="wikitable sortable plainrowheaders">
<caption>Film</caption>
<tr>
 <th scope="col">Year</th>
 <th scope="col">Title</th>
 <th scope="col">Role</th>
 <th scope="col" class="unsortable">Notes</th>
</tr>
<tr>
 <td style="text-align:center;">1997</td>
 <th scope="row"><i><span class="sortkey">Ice Storm, The</span><span class="vcard"><span class="fn"><a href="/wiki/The_Ice_Storm_(film)" title="The Ice Storm (film)">The Ice Storm</a></span> </span></i></th>
 <td>Libbets Casey</td>
 <td>First professional role</td>
</tr>
<tr>
 <td style="text-align:center;">1998</td>
 <th scope="row"><i><a href="/wiki/Disturbing_Behavior" title="Disturbing Behavior">Disturbing Behavior</a></i></th>
 <td>Rachel Wagner</td>
 <td><a href="/wiki/MTV_Movie_Award_for_Best_Breakthrough_Performance" title="MTV Movie Award for Best Breakthrough Performance">MTV Movie Award for Best Breakthrough Performance</a><br />
 Nominated–<a href="/wiki/Saturn_Award_for_Best_Performance_by_a_Younger_Actor" title="Saturn Award for Best Performance by a Younger Actor">Saturn Award for Best Performance by a Younger Actor</a>     </td>
</tr>

I'd like to look for the <span> tag with text 'Filmography' and then retrieve all the film links from the following table. 
Can I do this?

A:

Solution using Nokogiri#css selecting. (Probably not the most efficient way but it works)
require 'open-uri'
require 'nokogiri'

page = Nokogiri::HTML(open("http://en.wikipedia.org/w/index.php?title=Katie_Holmes&amp;action=edit&amp;section=10"))
puts page.css('span.mw-headline#Filmography').text

page.css('table').each do |tab|
  if tab.css('caption').text == "Film"
    tab.css('th').css('a').each do |a|
      puts "Title: #{a['title']} URL:#{a['href']}"
    end
  end
end

#=> Filmography
#=> Title: The Ice Storm (film) URL:/wiki/The_Ice_Storm_(film)
#=> Title: Disturbing Behavior URL:/wiki/Disturbing_Behavior
#=> .....So on

