Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting the anchor from a URL in ruby

Tags:

url

anchor

ruby

I looked through the documentation of the URI class in ruby but couldn't find a way to extract the anchor (HTML) from the instance. For example, in

http://example.com/index.php?q=something#anchor

I would like to get the anchor text. Trivial solution is to manipulate the text with regular expressions but if there is some method for it, then it's much better.

like image 205
allprog Avatar asked Jun 24 '13 23:06

allprog


1 Answers

The URI module provides a fragment attribute. e.g:

>> uri = URI("http://example.com/index.php?q=something#anchor")
>> uri.fragment
=> "anchor"
like image 61
pjumble Avatar answered Nov 04 '22 07:11

pjumble