Scrape Steam Screenshots

By PennyBreed on Mar 17, 2014

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);

Comments

Sign in to comment.
Hawkee   -  Mar 17, 2014

Shouldn't the uname be an input?

PennyBreed  -  Mar 18, 2014

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.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.