简体   繁体   English

如何在 Rails 上使用 Ruby 从 email 中提取所有 URls/链接?

[英]How can I extract all URls/links from an email using Ruby on Rails?

I am building a bookmarking site.我正在建立一个书签网站。 I want to extract all URIs/links from an email.我想从 email 中提取所有 URI/链接。 My site is in using Ruby on Rails.我的网站在 Rails 上使用 Ruby。

How can I extract all the URLs of received email content?如何提取收到的 email 内容的所有 URL?

Ruby's built-in URI module does this already: Ruby 的内置 URI 模块已经这样做了:

From the extract docs:extract文档中:

require "uri"

URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
# => ["http://foo.example.com/bla", "mailto:test@example.com"]
require 'uri'

text = %{"test
<a href="http://www.a.com/">http://www.a.com/</a>, and be sure
to check http://www.a.com/blog/. Email me at <a href="mailto:b@a.com">b@a.com</a>.}


END_CHARS = %{.,'?!:;}
p URI.extract(text, ['http']).collect { |u| END_CHARS.index(u[-1]) ? u.chop : u }

Source: http://www.java2s.com/Code/Ruby/Network/ExtractURL.htm来源: http://www.java2s.com/Code/Ruby/Network/ExtractURL.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ruby / rails ruby​​ / rails如何使用Twitter API从(用户的)Twitter LIST获取所有推文? - ruby/rails ruby/rails How can I get all the tweets from Twitter LIST (of users) using the Twitter API? 如何在Rails上使用ruby从redis获取所有匹配的密钥 - How can I get all matched keys from redis using ruby on rails 如何从使用Ruby on Rails中的方法获得的类模型中对Enumerable进行排序? - How can I sort an Enumerable from a class model obtained using method all in Ruby on Rails? 使用 Ruby/Rails 将链接从字符串转换为可点击的链接 - Convert links from a string to clickable links using Ruby/Rails 如何在Rails / Devise中为合作伙伴链接创建自定义登录页面URL? - How can I create custom login page URLs in Rails/Devise for partner links? 如何从Ruby / Rails项目中提取所有人类可读的字符串以进行拼写和语法检查? - How do I extract all human-readable strings from my Ruby/Rails project for spell and grammar checking? 如何从生成的 URL 中删除端口? 导轨 - How can I remove the port from generated URLs? rails 如何在Ruby on Rails命令行中列出所有REST URL - How to list all REST URLs in Ruby on Rails commanline Ruby on Rails:如何在服务器端从Redis获取所有会话数据? - Ruby on Rails: How can I get all sessions data from Redis on server side? 使用Dashes作为轨道上的红宝石中的URL - Using Dashes for urls in ruby on rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM