From: Pen Ttt on
/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?
--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
On 05.07.2010 04:00, Pen Ttt wrote:
> /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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/