Last active
August 12, 2020 20:29
-
-
Save 3gcodes/046ed1f5bd23bb632996663553bc14fd 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
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
const url = 'https://boardgamegeek.com/collection/user/gdboling'; | |
let ids = []; | |
let prices = []; | |
foo(); | |
console.log(prices); | |
async function foo() { | |
const response = await axios.get(url); | |
const data = response.data; | |
const $ = cheerio.load(data); | |
$('#collectionitems tbody tr td:nth-child(1)').each((idx, element) => { | |
const href = $(element).find('a').attr('href'); | |
const id = href.split('/')[2]; | |
ids.push(id); | |
}); | |
ids.map( async id => { | |
console.log('calling market for id', id); | |
const r2 = await axios.get('https://api.geekdo.com/api/geekmarket/products?ajax=1&browsetype=browse&colluserid=0&condition=any&country=any¤cy=any&displaymode=list&eventid=0&findmywants=0&inventorytype=any&marketdomain=boardgame&nosession=1&objectid=' + id + '&objecttype=thing&pageid=1&productstate=active&shiparea=any&sort=recent&stock=instock&userid=0'); | |
const market = r2.data; | |
const products = market.products; | |
let p = 0; | |
products.map(product => { | |
try { | |
p = p + parseFloat(product.price); | |
}catch(e) { | |
console.log(e); | |
} | |
prices.push(p / products.length) | |
}); | |
console.log('done with market for id', id); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment