标签: ruby url anchor
我查看了ruby中的documentation of the URI class,但找不到从实例中提取锚点(HTML)的方法。例如,在
http://example.com/index.php?q=something#anchor
我想获得anchor文字。简单的解决方案是使用正则表达式操作文本,但如果有一些方法,那就更好了。
anchor
答案 0 :(得分:9)
URI模块提供fragment属性。 e.g:
URI
fragment
>> uri = URI("http://example.com/index.php?q=something#anchor") >> uri.fragment => "anchor"