Jump to content

[SOLVED] Parsing Steam Community Profile


Recommended Posts

First we get the page source of the Steam Community Profile:

#include <INet.au3>

Func _SteamProfile_GetPageSource($sURL_SteamProfile)

    Local $s_siteSource = _INetGetSource($s_steamProfile);

    If ($s_siteSource = "") Then Return SetError(1, 0, "");

    Return SetError(0, 0, $s_siteSource);

EndFunc ;==>_SteamProfile_GetPageSource

The function will return a large amount of text, what we need is this section:

InGame

<!-- profile status bit -->
            <div id="OnlineStatus">

            <div id="inCommon">
                <div id="currentlyPlayingIcon">
                                        <div class="iconHolder_in-game"><div class="avatarIcon"><a href="http://store.steampowered.com/app/10180"><img src="http://media.steampowered.com/steamcommunity/public/images/apps/10180/ad502494f1658220f9166c7e17ac90422bf6a479.jpg" /></a></div></div>
                                    </div>
                <img src="http://steamcommunity.com/public/images/skin_1/status_in-game.gif" width="120" height="14" border="0" /><br />
                <p id="statusInGameText">
                    Call of Duty: Modern Warfare 2              </p>
                <br clear="left" />

</div>
</div>
<!-- /profile status bit -->

Offline

<!-- profile status bit -->
            <div id="OnlineStatus">

            <div id="inCommon">
                <p id="statusOfflineText">Last Online: 2 hrs, 1 mins ago</p>
</div>
</div>
<!-- /profile status bit -->

Online

<!-- profile status bit -->
            <div id="OnlineStatus">

            <div id="inCommon">
                <div id="statusOnlineText"><img src="http://steamcommunity.com/public/images/skin_1/status_online.gif" width="102" height="14" border="0" /></div><br />


</div>
</div>
<!-- /profile status bit -->

The thing is, I have zero experience in parsing html. What I need is being able to retrieve online status (online/offline), and if status is "InGame", I need to find out what game we're talking about. If you have any clues on how I can achieve this, please let me know! And I'm not asking you to write the code for me - I'm here to learn! (though, examples is always appreciated) :mellow:

Edited by Encoded
Link to comment
Share on other sites

I realize that regex might be the way to go, so what I need now is a pattern that returns everything between

<!-- profile status bit -->

... and ...

<!-- /profile status bit -->

My attempt:

#include <Array.au3>
#include <INet.au3>

Local $s_regexPattern = "^<!-- profile status bit -->$(.*?)^<!-- \/profile status bit -->$";

Local $a_regex = StringRegExp(_SteamProfile_GetPageSource("INSERT STEAM PROFILE URL HERE"), $s_regexPattern, 3, 1);

_ArrayDisplay($a_regex);

; ----------------------------------------------------------------------------------------------------
Func _SteamProfile_GetPageSource($sURL_SteamProfile)

    Local $s_siteSource = _INetGetSource($s_steamProfile);

    If ($s_siteSource = "") Then Return SetError(1, 0, "");

    Return SetError(0, 0, $s_siteSource);

EndFunc ;==>_SteamProfile_GetPageSource
; ----------------------------------------------------------------------------------------------------

The regex pattern does not work, any hints? I'm not sure about multiline matching in au3 regex :mellow:

Note: A Steam Community Profile URL can be obtained from here; http://steamcommunity.com/groups/Valve (I didn't find it appropriate to post a specific profile URL).

Link to comment
Share on other sites

StringBetween might be a better solution. Just find unique text at the beginning and end of what you're looking for, and keep whittling it down.

Something like this should work. Remember that double quotes " have to be doubled "" inside a quoted string.

StringBetween($text, "<div id=""OnlineStatus"">" , "</div>")

Since each snippet has the significant bits between OnlineStatus and the following closing </div> tag, that should give you what you need.

Link to comment
Share on other sites

Local $s_RegExPattern = "(?i)(?s)<.+profile\sstatus\sbit.+?>\v*(.+?)<.+/profile\sstatus\sbit"

By the way, it's a good place for StringRegExpReplace() too

$s_RegExPattern = "(?i)(?s).*<\!.+profile\sstatus\sbit.+?>\v*(.+?)<\!.+/profile\sstatus\sbit.*"
$s_Input = "<!-- profile status bit -->" & @CRLF
$s_Input &= '           <div id="OnlineStatus">' & @CRLF

$s_Input &= '            <div id="inCommon">' & @CRLF
$s_Input &= '                <div id="currentlyPlayingIcon">' & @CRLF
$s_Input &= "<!-- /profile status bit -->" ;; I cut part out for brevity but the same will work

$sData = StringRegExpReplace($s_Input, $s_RegExPattern, "$1")
If @Extended Then
    MsgBox(0,"result", $sData)
Else
    MsgBox(0, "Error", "No match to the regular expression")
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thank you for your assistance!

I have created working code for retrieving the name of the user, whether the user is online/offline/ingame (and what game),if offline, when the user was last online, and whether the profile is private or not. Doing the same thing in C# too. When I get the code free of bugs I'll see about posting everything here :mellow:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...