Rails中的元标记解析 [英] meta tag parsing in Rails

查看:130
本文介绍了Rails中的元标记解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一些东西来帮助我从类似于我找到开放的github项目的网站中解析通用元标记.图形数据.这是一个演示应用.

I was looking for something to help me parse general meta-tags from websites similar to this github project I found for open graph data. Here's a demo app.

基本上,我希望用户可以从新闻站点输入URL,并从标题中检索Desc,Desc等,从而为用户节省了尽可能少的工作.在我自己动手之前,我想知道是否存在与上述项目相似的当前项目/宝石? (因为它仅适用于开放图而不适用于通用元标记)

Basically, I'd like to be able to have a user input a URL from a news site and have it retrieve from that the Title, Desc, etc., leaving as little work possible for the user. Before I go roll my own I was wondering if there was a current project / gem that exists similar to the project above? (as it only works with open graph and not general meta-tags)

我还注意到,即使没有打开特定于图形的标签, facebook的短毛绒也能做到这一点.

I also noticed that facebook's linter does this as well even without open graph specific tags.

推荐答案

我建议使用 Nokogiri宝石 .它是HTML,XML等解析器,因此您可以使用它自己解析页面.这种方法的好处是,它可以为您的特定用例提供最大的灵活性.您可以使用gem来解析任何meta和header标记,只要您可以使用XPath或CSS3选择器来表达它们即可.

I would recommend the Nokogiri gem. It is an HTML, XML, etc. parser so you can use it to parse pages on your own. The nice thing about this approach is that it affords you the most flexibility for your specific use case. You can use the gem to parse any meta and header tags as long as you can express them using XPath or CSS3 selectors.

这篇关于Rails中的元标记解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆