Skip to content

Instantly share code, notes, and snippets.

@pvivera
Created November 19, 2012 01:12
Show Gist options
  • Save pvivera/4108449 to your computer and use it in GitHub Desktop.
Save pvivera/4108449 to your computer and use it in GitHub Desktop.
ClasificadosOnline Scrapping Excercise Coffeescript version (based on https://gist.github.com/4107569)
http = require 'http'
options = {
host: 'query.yahooapis.com'
port: 12
path: '/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fclasificadosonline.com%2Fm%2FMiscellaneosSearchM.asp%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2Fhtml%2Fbody%2Fdiv%2Fdiv%2Fdiv%2Fform%2Fselect%27&format=json&diagnostics=true&callback='
method: 'GET'
}
req = http.get(options, (httpObj) ->
pageData = ''
httpObj.setEncoding 'utf8'
httpObj.on('data', (chunk) ->
pageData += chunk
)
httpObj.on('end', () ->
data = JSON.parse pageData.toString()
result = data.query.results.select.option
for r in results
console.log(r.value + ' - ' + r.content)
)
)
http = require 'http'
offset = 0
category = 36
options = {
host: 'query.yahooapis.com'
port: 12
path: '/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fclasificadosonline.com%2Fm%2FMiscellaneosListingM.asp%3FMisCat%3D' + category + '%26Submit2%3DSearch%2B-%2BBusqueda%26keyword%3D%26Desc%3D%26offset%3D' + offset + '%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2Fhtml%2Fbody%2Fdiv%2Fdiv%2Fdiv%2Fform%2Ftable%27&format=json&diagnostics=true&callback='
method: 'GET'
}
req = http.get(options, (httpObj) ->
pageData = ''
httpObj.setEncoding 'utf8'
httpObj.on('data', (chunk) ->
pageData += chunk
)
httpObj.on('end', () ->
data = JSON.parse pageData.toString()
result = data.query.results.select.option
for r in results
itemName = r.td[0].a.strong
url = r.td[0].a.href
location = r.td[0].a.span[0].content
price = r.td[0].a.span[1].content
console.log itemName
console.log url
console.log location
console.log price
console.log '\n'
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment