# Need script: convert html-text to text

**URL:** <https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611>\
**Category:** Ruby\
**Created:** [January 4, 2006, 11:29am UTC](https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611 "2006-01-04T11:29:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![keal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@keal](https://www.ruby-forum.com/u/keal)\
**Post date:** [January 4, 2006, 11:29am UTC](https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611/1 "2006-01-04T11:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@keal](https://www.ruby-forum.com/u/keal)\
**Post date:** [January 4, 2006, 11:45am UTC](https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611/2 "2006-01-04T11:45:41Z")

</div>

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/](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.lang.ruby/browse\_frm/thread/e0fb1207f1814c77/37cd5e35a1ffb8d7?q=strip+HTML+tags&rnum=7#37cd5e35a1ffb8d7](http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/e0fb1207f1814c77/37cd5e35a1ffb8d7?q=strip+HTML+tags&rnum=7#37cd5e35a1ffb8d7)

---

<div class="post-metadata">

**Author:** ![keal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@keal](https://www.ruby-forum.com/u/keal)\
**Post date:** [January 4, 2006, 11:54am UTC](https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611/3 "2006-01-04T11:54:42Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![keal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@keal](https://www.ruby-forum.com/u/keal)\
**Post date:** [January 4, 2006, 12:00pm UTC](https://www.ruby-forum.com/t/need-script-convert-html-text-to-text/51611/4 "2006-01-04T12:00:43Z")

</div>

On Wed, 04 Jan 2006 10:30:03 -0000, keal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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,
