meta tag parsing in Rails [closed]

2019-07-19 13:14发布

问题:

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.

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)

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

回答1:

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.



回答2:

You can also try this free (for most) Open Graph API that I built: http://www.opengraph.io/