Ruby 抽取 HTML 文档中的所有 URL 地址

2015-10-23 0 571
Ruby 抽取 HTML 文档中的所有 URL 地址
require 'uri'

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


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

遇见资源网 ruby Ruby 抽取 HTML 文档中的所有 URL 地址 http://www.ox520.com/16521.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务