nokogiri extract text?

P

Pen Ttt

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 ?
 
L

Luis Parravicini

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

<html>

<body>

<p>

<br>
=A0 =A0hallo,world

=A0<br />

</p>

</body>

</html>

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

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

would you mind to finish it ?

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


--=20
Luis Parravicini
http://ktulu.com.ar/blog/
 
T

Ted Flethuseo

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>

=C3=A3=E2=82=AC=E2=82=AC=C3=A3=E2=82=AC=E2=82=AC<br>
hallo,world

=C3=A3=E2=82=AC=E2=82=AC <br />

</p>=C3=A3=E2=82=AC=E2=82=AC

</body>

</html>

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

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

would you mind to finish it ?

-- =

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

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top