A little node.js server to scrape latest screenshot links and descriptions from your Steam profile, and output a JSON object.
First, install the required packages.
npm install express
npm install request
npm install cheerio
Here is the node part. Be sure to change uname
to your steam id on line 8.
Once completed, and running - access the results like this: http://127.0.0.1:2080/screens
If you want to use an input variable, instead of a static user id, uncomment line 9 and comment or remove line 8 - then use a URL like this: http://127.0.0.1:2080/screens?uname=SomeUser
var express = require('express');
var $ = require('cheerio');
var request = require('request');
var app = express();
app.get('/screens', function(req, res) {
var uname = "TotalNewb"; //Change to your own steam id. Remove this line if you use the one below.
//var uname = req.query['uname']; //Or Uncomment this line to use an input variable
request("http://steamcommunity.com/id/"+uname+"/screenshots/", function(err, resp, html) {
if (err) { throw err; }
var parsedHTML = $.load(html);
var imageURLs = [];
parsedHTML('a').map(function(i, img) {
var imglink = $(img).attr('href');
var imgdesc = $(img).find('.ellipsis').html();
if (imgdesc) { imgdesc=imgdesc.replace(/^\s+|\s+$/g, ''); } //trim out any whitespace
if ($(img).hasClass('profile_media_item')) { imageURLs.push( { link: imglink, desc: imgdesc } ); }
});
res.send(JSON.stringify(imageURLs));
});
});
app.listen(2080);
In my particular case, I was using a static user id. However, I modified the snippet to allow for an input variable as well, if needed.