Skip to content

Instantly share code, notes, and snippets.

@jordanluyke
Last active February 2, 2018 22:54
Show Gist options
  • Save jordanluyke/6ab0ba47d1eadea93f138c0813a72c6c to your computer and use it in GitHub Desktop.
Save jordanluyke/6ab0ba47d1eadea93f138c0813a72c6c to your computer and use it in GitHub Desktop.
Nowinstock scraper
const Observable = require('rxjs').Observable
const request = require('request')
const cheerio = require('cheerio')
const moment = require('moment')
Observable.interval(1000 * 15)
.timeInterval()
.flatMap(Void => {
return Observable.create(observer => {
request({
url: "http://www.nowinstock.net/computers/videocards/nvidia/gtx1080ti/",
method: "GET"
}, (err, res, body) => {
if(err)
observer.error(err)
else if(!("" + res.statusCode).match(/2\d{2}/g))
observer.error(res)
else
observer.next(res)
})
})
})
.do(Void => console.log("=============== " + moment().format("h:mm:ss a") + " ==============="))
.flatMap(res => {
let $ = cheerio.load(res.body)
let rows = $("#data tr").get()
return Observable.from(rows)
})
.filter(row => !!row.attribs.id && row.children[2].children[0].data == "In Stock")
.do(row => {
let price = row.children[3].children[0].data
let name = row.children[1].children[0].children[0].data.slice(0, -2)
let link = row.children[1].children[0].attribs.href
console.log(price + " | " + name + " | " + link)
})
.subscribe(Void => {}, err => console.error("Error:", err.statusCode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment