Reputation: 4750
I'm using Ruby on Rails 2.3.8 and Hpricot plugin for parsing HTML.
I would like to get embedded videos thumbnails, and searching on the internet I figured out that youtube and vimeo at least uses OG (open graph) protocol, which provides meta tags that contains the video info (url, thumbnail, etc).
For example, if I had this video, I could read the following meta tag, using Hpricot plugin:
<meta property="og:image" content="http://b.vimeocdn.com/ts/101/345/101345354_200.jpg" />
So, using Hpricot I should be able to parse it as follows:
video_url = "http://vimeo.com/16430948"
video_page = Hpricot.parse(open(video_url))
element = video_page.search("//meta[@property='og:image']")
But I get an empty element instead.
Note: if you searched for video_page.search("//meta")
, it will find the one I want on the list...but using the previous syntax it won't.
Could anybody tell me how can I solve this?
Upvotes: 0
Views: 1624
Reputation: 149
I came across this question whilst having a similar problem with Hpricot and meta data.
In the end I had to change the xpath from //meta to /html/head to get my scraping working. Trying the same here seems to work.
video_page.at('/html/head/meta[@property="og:image"]')['content']
Returns your image's URL.
Upvotes: 2