从ruby中的URL中提取锚点

时间:2013-06-24 23:34:05

标签: ruby url anchor

我查看了ruby中的documentation of the URI class,但找不到从实例中提取锚点(HTML)的方法。例如,在

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

我想获得anchor文字。简单的解决方案是使用正则表达式操作文本,但如果有一些方法,那就更好了。

1 个答案:

答案 0 :(得分:9)

URI模块提供fragment属性。 e.g:

>> uri = URI("http://example.com/index.php?q=something#anchor")
>> uri.fragment
=> "anchor"