Skip to content

Instantly share code, notes, and snippets.

@duyet
Last active August 29, 2015 14:08
Show Gist options
  • Save duyet/027368e0fff8cd295d26 to your computer and use it in GitHub Desktop.
Save duyet/027368e0fff8cd295d26 to your computer and use it in GitHub Desktop.
lib =
fs : require('fs')
u : require('underscore')
https : require('https')
url : require('url')
appendToFile = (data) ->
lib.fs.open 'fbdata', 'a', (e, fd) ->
lib.fs.write fd, data, null, 'utf8', ->
lib.fs.close fd, ->
facebookCrawl(JSON.parse(data).paging.next)
facebookCrawl = (link) ->
url = lib.url.parse(link)
lib.https.get {host:url.host, path:url.path}, (res) ->
res.setEncoding('utf8')
body = ""
res.on('data', (d) -> body += d)
res.on('end', -> appendToFile(body))
res.on('error', (e) -> console.log("https error: #{e}"))
# Start crawler
accessToken = ""
facebookCrawl("https://graph.facebook.com/me/feed?access_token=#{accessToken}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment