从ruby中的URL中提取锚点

时间:2022-11-27 17:51:15

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

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

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.

我想得到锚文本。简单的解决方案是使用正则表达式操作文本,但如果有一些方法,那么它会好得多。

1 个解决方案

#1


9  

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

URI模块提供片段属性。例如:

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

#1


9  

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

URI模块提供片段属性。例如:

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