Skip to content

Instantly share code, notes, and snippets.

@liamcurry
Created October 17, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamcurry/a6efa007d5910a8c0c8b to your computer and use it in GitHub Desktop.
Save liamcurry/a6efa007d5910a8c0c8b to your computer and use it in GitHub Desktop.
request = require 'request'
_ = require 'lodash'
Nightmare = require 'nightmare'
nightmare = new Nightmare()
findImages = (link) ->
nightmare
.goto link
.wait()
#.evaluate getImages, logImages
.evaluate ->
document.body
, (r) -> console.log r
.url (u) -> console.log u, link
#.screenshot 'ss.png'
.run (err, nightmare) -> console.log 'Done.'
getImages = ->
imgs = document.querySelectorAll 'img'
resp = []
for img in imgs
rect = img.getBoundingClientRect()
resp.push
width: rect.width
height: rect.height
area: rect.width * rect.height
top: rect.top
bottom: rect.bottom
src: img.src
resp
logImages = (resp) ->
console.log resp
max = _.max resp, (i) -> i.area
console.log JSON.stringify(resp)
console.log 'largest image:', max
FeedParser = require('feedparser')
parser = ->
feedparser = new FeedParser()
feedparser.on 'error', (error) -> console.log 'feed error', error
feedparser.on 'readable', ->
@emit 'data', 'testing'
#console.log item.link while item = @read()
findImages item.link while item = @read()
fetch = (uri) ->
console.log "requesting #{uri}"
req = request uri
req.pipe parser()
fetch 'http://news.ycombinator.com/rss'
#findImages 'http://kayak.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment