strange xpath output

P

Pen Ttt

/home/pt/jiexi content is:
<ul id="ul_list">
<li class="expli"><a href="tv_play-hdteleplay_20100211_7168444.html"
title="ok1"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168445.html"
title="ok2"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168446.html"
title="ok3"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168447.html"
title="ok4"></a></li>
</ul>

require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML.parse(open('/home/pt/jiexi'))
table=doc.xpath('//ul[@id="ul_list"]/li/a')
puts table
output
irb(main):005:0> puts table
<a href="tv_play-hdteleplay_20100211_7168444.html" title="ok1"></a>
<a href="tv_play-hdteleplay_20100211_7168445.html" title="ok2"></a>
<a href="tv_play-hdteleplay_20100211_7168446.html" title="ok3"></a>
<a href="tv_play-hdteleplay_20100211_7168447.html" title="ok4"></a>
=> nil
puts table.xpath('//ul')
irb(main):006:0> puts table.xpath('//ul')
<ul id="ul_list">
<li class="expli"><a href="tv_play-hdteleplay_20100211_7168444.html"
title="ok1"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168445.html"
title="ok2"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168446.html"
title="ok3"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168447.html"
title="ok4"></a></li>
</ul>

what i think is the script "puts table.xpath('//ul')" will not create
any output.
how strange it is to get the result,would you mind to tell me why?
 
R

Robert Klemme

/home/pt/jiexi content is:
<ul id="ul_list">
<li class="expli"><a href="tv_play-hdteleplay_20100211_7168444.html"
title="ok1"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168445.html"
title="ok2"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168446.html"
title="ok3"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168447.html"
title="ok4"></a></li>
</ul>

require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML.parse(open('/home/pt/jiexi'))
table=doc.xpath('//ul[@id="ul_list"]/li/a')
puts table
output
irb(main):005:0> puts table
<a href="tv_play-hdteleplay_20100211_7168444.html" title="ok1"></a>
<a href="tv_play-hdteleplay_20100211_7168445.html" title="ok2"></a>
<a href="tv_play-hdteleplay_20100211_7168446.html" title="ok3"></a>
<a href="tv_play-hdteleplay_20100211_7168447.html" title="ok4"></a>
=> nil
puts table.xpath('//ul')
irb(main):006:0> puts table.xpath('//ul')
<ul id="ul_list">
<li class="expli"><a href="tv_play-hdteleplay_20100211_7168444.html"
title="ok1"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168445.html"
title="ok2"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168446.html"
title="ok3"></a></li>
<li><a href="tv_play-hdteleplay_20100211_7168447.html"
title="ok4"></a></li>
</ul>

what i think is the script "puts table.xpath('//ul')" will not create
any output.
how strange it is to get the result,would you mind to tell me why?

That's perfectly expected. If you look closely at the eplanation,
you'll find out:

http://www.w3schools.com/Xpath/xpath_syntax.asp

You probably wanted

puts table.xpath('ul')

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top