加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 通过rails中的链接获取标题,内容

发布时间:2020-12-17 01:46:01 所属栏目:百科 来源:网络整理
导读:我刚开始学习rails.你能帮我理解解析一个链接吗?好的教程也会有所帮助…… 问题: 当您在Digg,Facebook等中提交链接时.在您说附加链接后,它会解析链接以获取特定网址的标题,内容和图像.你能帮我解决一下在rails中如何实现类似的东西吗? 我看过饲料解析器,
我刚开始学习rails.你能帮我理解解析一个链接吗?好的教程也会有所帮助……

问题:

当您在Digg,Facebook等中提交链接时.在您说附加链接后,它会解析链接以获取特定网址的标题,内容和图像.你能帮我解决一下在rails中如何实现类似的东西吗?

我看过饲料解析器,如feedzirra等,但他们似乎得到了完整的网站提供..不仅仅是我们正在寻找的链接..还是我在某处犯了错误?

非常感谢提前.

解决方法

看起来你可能正在寻找像Pismo: https://github.com/peterc/pismo这样的东西

require 'pismo'

# Load a Web page (you could pass an IO object or a string with existing HTML data along,as you prefer)
doc = Pismo::Document.new('http://www.rubyinside.com/cramp-asychronous-event-driven-ruby-web-app-framework-2928.html')

doc.title     # => "Cramp: Asychronous Event-Driven Ruby Web App Framework"
doc.author    # => "Peter Cooper"
doc.lede      # => "Cramp (GitHub repo) is a new,asynchronous evented Web app framework by Pratik Naik of 37signals (and the Rails core team). It's built around Ruby's EventMachine library and was designed to use event-driven I/O throughout - making it ideal for situations where you need to handle a large number of open connections (such as Comet systems or streaming APIs.)"
doc.keywords  # => [["cramp",7],["controllers",3],["app",["basic",2],...,... ]

图像警告是:

The image extraction only deals with images with absolute URLs

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读