我查看了 Ruby 中 URI 类的文档,但是没有找到从实例中提取锚点(HTML)的方法。例如,在 http://example.com/index.php?q=something#anchor 我希望获得 锚文本。处理文本的常规方法是使用正则表达式,但如果有其他方法那就更好了。
URI模块提供了fragment属性,例如:URI和fragment。>> uri = URI("http://example.com/index.php?q=something#anchor") >> uri.fragment => "anchor"