gpt4 book ai didi

ruby-on-rails - 如何过滤掉与方案匹配的 URI?

转载 作者:数据小太阳 更新时间:2023-10-29 08:58:32 25 4
gpt4 key购买 nike

这是 Ruby on Rails 应用程序的 ActiveJob/

我正在使用 Anemone 网络爬虫,并在 www.example.com 的主页上创建了所有 URI 的数组。我想过滤掉那些没有特定路径的。

所以 www.example.com/somepath 应该被挑选出来保存,而 www.example.com/someotherpath 不应该被挑选出来保存。

问题是我不能不过滤这些数组条目。没有我可以对它们使用的正则表达式方法。

我在顶部需要'uri',但仍然收到方法不存在错误。

最佳答案

使用数组的 select 和 String 的 include 来完成这项艰巨的工作。

your_array = [ URI('www.example.com/somepath'),
URI('www.example.com/someotherpath') ]
filter = 'somepath'

your_array.select { |t| t.to_s.include?(filter) }

=> [URI("www.example.com/somepath")]

关于ruby-on-rails - 如何过滤掉与方案匹配的 URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com