Skip to content

Instantly share code, notes, and snippets.

@gazs
Created April 23, 2011 09:08
Show Gist options
  • Select an option

  • Save gazs/938487 to your computer and use it in GitHub Desktop.

Select an option

Save gazs/938487 to your computer and use it in GitHub Desktop.
http = require 'http'
sets = (items, callback) ->
c = 0
query = items.map (i) ->
c += 1
return "q#{c}=#{i}"
.join('&')
options =
host: 'labs.google.com'
port: 80
path: "/sets?hl=en&btn=Large+Set&#{query}"
http.get options, (res) ->
body = ""
res.on 'data', (chunk) -> body += chunk
res.on 'end', ->
re = /<a href="http:\/\/www\.google\.com\/search\?hl=en&amp;q=[^"]+">(.*?)<\/a>/g
matches = body.match re
results = []
for match in matches
try
results.push re.exec(match)[1]
catch e # na de miért?
callback results
sets ['alma', 'körte', 'barack'], console.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment