Created
October 17, 2014 19:05
-
-
Save liamcurry/a6efa007d5910a8c0c8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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