title: Nokogiri and xpath parsing an HTML table
body: <p>I can set up parsing, and connect to a site but, when I run the script,
  it returns an empty NodeSet:</p>
  
  <pre><code>require 'rubygems'
  require 'mechanize'
  require 'nokogiri'
  require 'ap'
  
  time = Time.new
  
  url = &lt;&lt;-EOS
  'http://www.events.psu.edu/cgi-bin/cal/webevent.cgi?cmd=listday&amp;y=%d&amp;m=%d&amp;d=%d&amp;cat=&amp;sib=1&amp;sort=m,e,t&amp;ws=0&amp;cf=list&amp;set=1&amp;swe=1&amp;sa=1&amp;de=1&amp;tf=0&amp;sb=1&amp;stz=Default&amp;cal=cal299' % [time.year, time.month, time.day]
  EOS
  
  page = Nokogiri::HTML(url)
  
  rows =  page.xpath('/html/body/p/table/tbody/tr/td[3]/p/table/tbody/tr[2]')
  details = rows.collect do |row|
  detail = {}
  [
   [:time, 'td[3]/p/text()'],
   [:name, 'td[4]/div/a/b/font/text()'],
   [:location, 'td[4]/div[2]/text()'],
   [:details, 'td[4]/div[4]/text()'],
  ].collect do |name, xpath|
  
  detail[name] = row.at_xpath(xpath).to_s.strip
  end
  detail
  end
  ap details
  </code></pre>
  
  <p>The returned value is <code>"[]"</code>.</p>
  
  <p>This is the HTML file before the table <code>/html/body/p/table/tbody/tr/td[3]/p</code>:</p>
  
  <pre><code>&lt;TABLE BORDER=0 CELLPADDING=3 WIDTH="100%"&gt;
  
  &lt;!--Begin Event--&gt;
  &lt;TR&gt;
    &lt;TD WIDTH="2%"&gt;
      &lt;P&gt;&lt;/P&gt;
    &lt;/TD&gt;
    &lt;TD WIDTH="10%"&gt;
      &lt;P&gt;&lt;/P&gt;
    &lt;/TD&gt;
    &lt;TD WIDTH="19%"&gt;
  
      &lt;P&gt;&lt;/P&gt;
    &lt;/TD&gt;
    &lt;TD WIDTH="60%"&gt;
      &lt;P&gt;&lt;/P&gt;
    &lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
  &lt;!--Icon Section--&gt;
    &lt;TD CLASS="listeventbg" VALIGN=top WIDTH="2%"&gt;
      &lt;P CLASS="listeventicon"&gt;&amp;nbsp;&lt;/P&gt;
  
    &lt;/TD&gt;
  &lt;!--Date Section--&gt;
    &lt;TD CLASS="listeventbg" VALIGN=top WIDTH="10%"&gt;
      &lt;P CLASS="listeventdate"&gt;Mar 14&lt;/P&gt;
    &lt;/TD&gt;
  &lt;!--Time Section--&gt;
    &lt;TD CLASS="listeventbg" VALIGN=top WIDTH="19%"&gt;
      &lt;P CLASS="listeventtime"&gt;8:30 a.m. - 4:30 p.m.&lt;BR&gt;
  &lt;/P&gt;
  
    &lt;/TD&gt;
  &lt;!--Main Event Section--&gt;
    &lt;TD CLASS="listeventbg" VALIGN=top WIDTH="60%"&gt;
  &lt;div class=listeventtitlelarge&gt;&lt;A HREF="http://www.pennstatehershey.org/web/diabetesresearch/home"&gt;
  &lt;B&gt;&lt;font color="#0000CC"&gt;2011 Diabetes and Obesity Research Spring Summit&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;
  &lt;/div&gt;
  &lt;div class=listeventtitle&gt;&lt;B&gt;Calendar:&lt;/B&gt; HHD Seminars&lt;BR&gt;
  &lt;B&gt;Posted by:&lt;/B&gt; &lt;A HREF="mailto:luk10%40psu.edu"&gt;Lauren Kipp&lt;/A&gt;&lt;BR&gt;&lt;B&gt;Location:&lt;/B&gt; The Nittany Lion Inn&lt;BR&gt;
  
  &lt;/div&gt;
  &lt;DIV CLASS="listeventspacer"&gt; &lt;/DIV&gt;
  &lt;DIV CLASS="listeventdetails"&gt;
  &lt;B&gt;Details:&lt;/B&gt;&lt;BR&gt;Registration and Abstract Deadline: February 15, 2011&lt;BR&gt;        &lt;BR&gt;Registration: Please follow the link for more details and access to on line registration. Space is limited, so please register early to ensure your seat at the conference.&lt;BR&gt;&lt;BR&gt;The Keynote Speaker for this year’s event is &lt;b&gt;Dr. Robert Sherwin, from the Yale School of Medicine.&lt;/b&gt;  Dr. Sherwin is known for his research in the effect of insulin on brain function and immune mechanisms leading to type 1 diabetes.  The topic of his presentation is &lt;i&gt;Pathophysiological Mechanisms in Diabetes, from Laboratory to Bedside.&lt;/i&gt;&lt;BR&gt;&lt;BR&gt;A welcome to the University Park campus will be offered by &lt;b&gt;Eugene Marsh, MD&lt;/b&gt;, Senior Associate Dean for the Penn State College of Medicine Regional Medical Campus and Associate Director of the Penn State Hershey Medical Group in State College&lt;BR&gt;&lt;BR&gt;Abstract Submission&lt;BR&gt;Please follow the link for formatting details and to register your intent to submit an abstract using the on-line form.&lt;BR&gt;    &lt;BR&gt;You will receive a confirmation immediately upon submission of your on-line form. Subsequently, the final formatted abstract must be sent directly to Continuing Ed by email attachment (see website instructions). Within 48 hours of sending your abstract in final format, you will receive an email confirmation from ContinuingEd@hmc.psu.edu indicating that both your form &amp; the abstract attachment have been received.&lt;BR&gt;&lt;BR&gt;&lt;i&gt;All abstracts will be considered for poster presentations. A subset of these abstracts will be selected and invited for brief oral presentations during the “Poster Headlines” plenary sessions. To be considered for an oral presentation, please be sure to meet the submission deadline for submission of your final abstract. Prizes will be awarded for the top three posters from by post-doc/fellow/student presenters.&lt;/i&gt;
  
  &lt;/div&gt;
  &lt;/TD&gt;
  &lt;!--EndEvent--&gt;
  ......Followed by more of the same format
  </code></pre>
  
  <p>I am trying to get the name of the event, the time, location and the description of the event.</p>