Skip to content

Instantly share code, notes, and snippets.

@naoya
Created October 19, 2011 10:13
Show Gist options
  • Save naoya/1297897 to your computer and use it in GitHub Desktop.
Save naoya/1297897 to your computer and use it in GitHub Desktop.
Scraping OpenGraph w/ node + jsdom + jQuery
jsdom = require 'jsdom'
jsdom.env
html: 'http://b.hatena.ne.jp/articles/201110/6114'
scripts: [ 'http://code.jquery.com/jquery-1.6.4.min.js' ]
done: (errors, window) ->
$ = window.$
og = {}
$('meta[property^="og:"]').each () ->
og[ $(@).attr('property').match(/og:(.+)$/)[1] ] = $(@).attr 'content'
console.log og.title
console.log og.url
console.log og.image
@ralyodio
Copy link

can you not get the attributes with querySelector? its not working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment