-
-
Notifications
You must be signed in to change notification settings - Fork 13
Create a module
In this example we will create a module for changing the profile image of the each account. The page 'http://steamcommunity.com/actions/GameAvatars/' have a collection off image from game's that the locked in accout have.
- Enter page 'http://steamcommunity.com/actions/GameAvatars/'
- Click a image
- Submit profile image.
- Enter 'http://steamcommunity.com/actions/GameAvatars/' get the html off the page.
- each image is just a normal link to a other page
- the submit is a formular, that send a Post request, to the games url like 'https://steamcommunity.com/games/TF2/selectAvatar', this data 'selectedAvatar, sessionid'.
- Load 'http://steamcommunity.com/actions/GameAvatars/', and get html content
- get a url for a avatar.
- load that url
- get form data. 'action' and input name 'selectedAvatar'
- send post to the 'action' from 4. and 'selectedAvatar' from 4. and 'sessionid' that the module give you
- add default data to module
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
//for next step
};
- now we need to load the first page:
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
var url = "http://steamcommunity.com/actions/GameAvatars/";
RequestCommunity.get({uri: url}, function(error, response, body) {
//for next step
})
};
Here the body tag, have the html of the hole page. 3. we need at way to easy read the page, and find what we need. We do that using npm module 'cheerio' that is like Jquery. That way we can use Jquery to finde a random image, and get the url. each image have class 'oggAvatar' that way we just need to find a random one, of the tags.
var cheerio = require('cheerio');
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
var url = "http://steamcommunity.com/actions/GameAvatars/";
RequestCommunity.get({uri: url}, function(error, response, body) {
var $ = cheerio.load(body);
var avatarIndex = Math.floor(Math.random() * ($(".oggAvatar").length - 1));
var gameAvatarUrl = $(".oggAvatar").eq(avatarIndex).find("a").attr("href");
//for next step
});
}
- now we just need to load that page, and get the content
var cheerio = require('cheerio');
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
var url = "http://steamcommunity.com/actions/GameAvatars/";
RequestCommunity.get({uri: url}, function(error, response, body) {
var $ = cheerio.load(body);
var avatarIndex = Math.floor(Math.random() * ($(".oggAvatar").length - 1));
var gameAvatarUrl = $(".oggAvatar").eq(avatarIndex).find("a").attr("href");
RequestCommunity.get({uri: gameAvatarUrl}, function(formError, formResponse, formBody) {
var $form = cheerio.load(formBody);
//for next step
});
});
}
here we just do as before, use RequestCommunity.get, to get page html. and add it into a jquery $form 5. now we just need to find the form in the html content, and get the action url, and the selectedAvatar input value
var cheerio = require('cheerio');
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
var url = "http://steamcommunity.com/actions/GameAvatars/";
RequestCommunity.get({uri: url}, function(error, response, body) {
var $ = cheerio.load(body);
var avatarIndex = Math.floor(Math.random() * ($(".oggAvatar").length - 1));
var gameAvatarUrl = $(".oggAvatar").eq(avatarIndex).find("a").attr("href");
RequestCommunity.get({uri: gameAvatarUrl}, function(formError, formResponse, formBody) {
var $form = cheerio.load(formBody);
var formHtml = $form("#avatarForm"); // find an id named avatarForm
var formUrl = formHtml.attr("action"); // get the value of the attribute 'action'
var selectedAvatar = formHtml.find("[name='selectedAvatar']").attr("value"); // find a element that have a attribute called 'name' and the value is selectedAvatar. and the that elements other attribute called 'value'
//for next step
});
});
}
what we can see is the form have a id 'avatarForm'. when just use jquery to finde the id. and get the action url. 6. now we have all the info we need, we have the url, selectedAvatar and sessionId. we just have to send the post
var cheerio = require('cheerio');
module.exports = function(steamClient, RequestCommunity, RequestStore, SessionID, options, callback){
var url = "http://steamcommunity.com/actions/GameAvatars/";
RequestCommunity.get({uri: url}, function(error, response, body) {
var $ = cheerio.load(body);
var avatarIndex = Math.floor(Math.random() * ($(".oggAvatar").length - 1));
var gameAvatarUrl = $(".oggAvatar").eq(avatarIndex).find("a").attr("href");
RequestCommunity.get({uri: gameAvatarUrl}, function(formError, formResponse, formBody) {
var $form = cheerio.load(formBody);
var formHtml = $form("#avatarForm");
var formUrl = formHtml.attr("action");
var selectedAvatar = formHtml.find("[name='selectedAvatar']").attr("value");
RequestCommunity.post({
url: formUrl, // post url
form:{ // data to send whit the post
selectedAvatar: selectedAvatar, // the new avartar
sessionid: SessionID // the account sessionID
}
}, function (postErr, postHttpResponse, postBody) {
callback(); // callback when done! to ensure the flow go to next module or account
});
});
});
}
- Chance profile settings
- Chance setting on the general edit page (Edit Profile)
- Chance mini profile
- Chance profile theme
- Chance profile favorite badge
- Chance profile favorite group
- Clear profile name alias
- Chance profile image