1- using SteamLib . Core ;
1+ using System . Diagnostics . CodeAnalysis ;
2+ using System . Text . RegularExpressions ;
3+ using SteamLib . Core ;
24using SteamLib . Exceptions . General ;
35using SteamLib . Web . Models . GlobalMarketInfo ;
46using SteamLib . Web . Scrappers . HTML ;
7+ using System . Threading ;
8+ using JetBrains . Annotations ;
9+ using HtmlAgilityPack ;
10+ using SteamLib . Core . Models ;
511
612namespace SteamLib . Web ;
713
@@ -26,4 +32,29 @@ public static async Task<GlobalInfoModel> GetMarketGlobalInfo(HttpClient client,
2632 throw new UnsupportedResponseException ( resp , ex ) ;
2733 }
2834 }
35+
36+
37+ [ RegexPattern ]
38+ [ SuppressMessage ( "ReSharper" , "UseRawString" ) ]
39+ [ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ]
40+ private static readonly string _regexTip =
41+ @"g_sessionID = ""(?<g_sessionID>.*)"";"
42+ + @"\s*g_steamID = (?<g_steamID>.*);" ;
43+
44+ private static readonly Regex Regex = new ( _regexTip , RegexOptions . Compiled ) ;
45+ private const string XPATH = "//div[@class='responsive_page_content']/script" ;
46+
47+ public static async Task < string > GetLoginSessionId ( HttpClient client , CancellationToken cancellationToken = default )
48+ {
49+ var resp = await client . GetStringAsync ( "https://steamcommunity.com/login/home" , cancellationToken ) ;
50+
51+ var document = new HtmlDocument ( ) ;
52+ document . LoadHtml ( resp ) ;
53+ var scriptNode = document . DocumentNode . SelectSingleNode ( XPATH ) ?? throw new NullReferenceException ( "Script Node was null" ) ;
54+ var script = scriptNode . InnerText ;
55+ var match = Regex . Match ( script ) ;
56+ if ( ! match . Success )
57+ throw new UnsupportedResponseException ( script , "Page contains script but regex was unsuccessful" ) ;
58+ return match . Groups [ "g_sessionID" ] . Value ;
59+ }
2960}
0 commit comments