Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   need script: convert html-text to text (http://www.velocityreviews.com/forums/t827483-need-script-convert-html-text-to-text.html)

keal 01-04-2006 10:30 AM

need script: convert html-text to text
 
i have html-text. i have to convert this text to simple text without
html-tags.

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



Gene Tani 01-04-2006 10:40 AM

Re: need script: convert html-text to text
 

keal wrote:
> i have html-text. i have to convert this text to simple text without
> html-tags.
>
> --
> Posted via http://www.ruby-forum.com/.


path o'least resistance

lynx -dump www.myurl
or use links2 ## or w3m -dump www.myurl

or high-falutin solution
http://groups.google.com/group/comp....cd5e35a1ffb8d7


Ross Bamford 01-04-2006 10:49 AM

Re: need script: convert html-text to text
 
On Wed, 04 Jan 2006 10:30:03 -0000, keal <keal21@mail.ru> wrote:

> i have html-text. i have to convert this text to simple text without
> html-tags.
>


It's tricky, there's more to it than you'd think. The best way is probably
to use Lynx, or another browser, to do it for you, e.g.:

def plain(url)
`lynx -dump "#{url}"`
end

p = plain('http://www.google.com/')
puts p

Outputs:

[1]Personalised Home | [2]Sign in

[3]A picture of the Braille letters spelling out "Google." Happy Birthday
Louis Braille!

Web [4]Images [5]Groups [6]News [7]Froogle [8]more ยป

> ... [snip] ...


Of course you'll need lynx for that to work, but you can use others too.
Try a Google search.

Cheers,

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Robert Klemme 01-04-2006 10:51 AM

Re: need script: convert html-text to text
 
keal wrote:
> i have html-text. i have to convert this text to simple text without
> html-tags.


This is a very low cost variant - I guess the lynx approach is much more
effective and complete:

ruby -pe 'gsub! %r{</?.*?>}, ""' index.html

Kind regards

robert



All times are GMT. The time now is 10:56 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.