Nokogiri extract text?

there is a simple file /home/pt/test.html such as the following

<html>

<body>

<p>

<br>
    hallo,world

<br />

</p>

</body>

</html>

i want to extract the text "hallo,world" in the /home/pt/test.html with
nokogiri,how to write?

require 'rubygems'
require 'nokogiri'
html = '/home/pt/test.html'
doc = Nokogiri::HTML(html)

would you mind to finish it ?

···

--
Posted via http://www.ruby-forum.com/.

At http://wiki.github.com/tenderlove/nokogiri/ you can read on how to
find the nodes you need. I think you'll need to use xpath.

Bye

···

On Wed, Jun 23, 2010 at 12:23 AM, Pen Ttt <myocean135@yahoo.cn> wrote:

there is a simple file /home/pt/test.html such as the following

<html>

<body>

<p>

<br>
hallo,world

<br />

</p>

</body>

</html>

i want to extract the text "hallo,world" in the /home/pt/test.html with
nokogiri,how to write?

require 'rubygems'
require 'nokogiri'
html = '/home/pt/test.html'
doc = Nokogiri::HTML(html)

would you mind to finish it ?

--
Luis Parravicini
http://ktulu.com.ar/blog/

If you just want to extract some specific text within a specific tag you
should go with what Luis posted.

If you want to extract the whole plain text from a specific area in your
document, not knowing which tags may occur, you can try this:
http://www.nils-haldenwang.de/frameworks-and-tools/nokogiri/how-to-extract-plain-text-from-html-with-nokogiri

···

--
Posted via http://www.ruby-forum.com/.

I do it like this:

puts doc.search('p').map { |e| e.text }

Pen Ttt wrote in post #920908:

···

there is a simple file /home/pt/test.html such as the following

<html>

<body>

<p>

  <br>
    hallo,world

  <br />

</p> 

</body>

</html>

i want to extract the text "hallo,world" in the /home/pt/test.html with
nokogiri,how to write?

require 'rubygems'
require 'nokogiri'
html = '/home/pt/test.html'
doc = Nokogiri::HTML(html)

would you mind to finish it ?

--
Posted via http://www.ruby-forum.com/\.