# Easy way for a Nuub to get link-element from a html-source

**URL:** <https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272>\
**Category:** Ruby\
**Created:** [November 26, 2007, 11:23am UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272 "2007-11-26T11:23:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 11:23am UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/1 "2007-11-26T11:23:39Z")

</div>

hi all.

im very new to ruby and im not sure how to do this the easiest way in  
ruby. i want to read the content from e.g. “[www.spiegel.de](http://www.spiegel.de)” and just  
this line

and from this line the “title” and the “href”

since the order in “link” is not sure, it doesnt look like regexp is the  
first choice. and i couldn’t find a HTML::Parse.

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 11:57am UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/2 "2007-11-26T11:57:01Z")

</div>

Marcus S. wrote:

> since the order in “link” is not sure, it doesnt look like regexp is the  
> first choice. and i couldn’t find a HTML::Parse.

Check out hpricot.

[http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)

Regards,  
Lee

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 12:18pm UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/3 "2007-11-26T12:18:47Z")

</div>

On 26.11.2007, at 11:23, Marcus S. wrote:

> and from this line the “title” and the “href”
> 
> since the order in “link” is not sure, it doesnt look like regexp is  
> the  
> first choice. and i couldn’t find a HTML::Parse.

How about hpricot?

[http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)

- Kai Brust

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/4 "2007-11-26T12:38:24Z")

</div>

> How about hpricot?
> 
> [http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)

ok, hpricot then.

is it just

gem install hpricot ??

or do i need to install this “ragel”-thing too?? (and if so which which  
is the best way to do so??)

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/5 "2007-11-26T14:24:02Z")

</div>

> Another possibility is scRUBYt!:

That looks good. That looks good. Thank you!

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 12:48pm UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/6 "2007-11-26T12:48:48Z")

</div>

Marcus S. wrote:

> since the order in “link” is not sure, it doesnt look like regexp is the  
> first choice. and i couldn’t find a HTML::Parse.

Another possibility is scRUBYt!:

==========================================  
require ‘rubygems’  
require ‘scrubyt’

feed\_data = Scrubyt::Extractor.define do  
fetch ‘[http://www.spiegel.de/](http://www.spiegel.de/)’

link “//link[@rel=‘alternate’]” do  
title “title”, :type =\> :attribute  
href “href”, :type =\> :attribute  
end  
end

# puts feed\_data.to\_xml

output:

==========================================

 SPIEGEL ONLINE als RSS-Feed http://www.spiegel.de/schlagzeilen/rss/index.xml ==========================================

or, to\_hash:

# ========================================== [{:title=\>“SPIEGEL ONLINE als RSS-Feed”, :href=\>“[DER SPIEGEL - Schlagzeilen](http://www.spiegel.de/schlagzeilen/rss/index.xml)”}]

Cheers,  
Peter

* * *

[http://www.rubyrailways.com](http://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)

---

<div class="post-metadata">

**Author:** ![strube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@strube](https://www.ruby-forum.com/u/strube)\
**Post date:** [November 26, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/easy-way-for-a-nuub-to-get-link-element-from-a-html-source/121272/7 "2007-11-26T14:58:34Z")

</div>

Marcus S. wrote:

> > Another possibility is scRUBYt!:
> 
> That looks good. That looks good. Thank you!

Hm yeah, but the downside (as of the recent version - it’ll be fixed in  
the next one) is that the installation process is somewhat… hmm… not  
that easy (mainly if you are on win32). If you still decide to go for  
scRUBYt!, we can talk on #scrubyt @ [irc.freenode.net](http://irc.freenode.net) or you can ask your  
questions in the forum ([http://agora.scrubyt.org](http://agora.scrubyt.org)).

Cheers,  
Peter

* * *

[http://www.rubyrailways.com](http://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)
