static async Task Main(string[] args) { try { string baseUri = "https://steamcommunity.com/market/search/render/"; Dictionary <string, string> paramsDict = new Dictionary <string, string>() { { "norender", "1" }, { "appid", "582810" }, { "sort_column", "name" }, { "sort_dir", "asc" }, }; MarketplaceQuery query = new MarketplaceQuery(baseUri, paramsDict); //SMParser.AddCookiesHeader("steamLoginSecure=76561198118722085%7C%7CD54F537019294E081A349BCA6DBF130B11695A67"); await SMParser.ParseToExcel(query, true); } catch (Exception e) { Console.WriteLine("Exception occured! More info:"); Console.WriteLine(e.Message); Console.WriteLine("Press any key to close"); Console.ReadKey(); } }
private async static Task <MarketplaceList> ParsePage(MarketplaceQuery query) { MarketplaceList items = new MarketplaceList(); string responseBody = await Client.GetStringAsync(query.Uri); MarketplaceQueryResponse response = JsonSerializer.Deserialize <MarketplaceQueryResponse>(responseBody); Console.WriteLine("Returned {0} items", response.results.Count); response.AddToMarketplaceList(items); return(items); }
public async static Task <MarketplaceList> ParseTolist(MarketplaceQuery query) { MarketplaceList items = new MarketplaceList(); query.AddParam("start", 0); query.AddParam("count", 100); string responseBody = await Client.GetStringAsync(query.Uri); MarketplaceQueryResponse response = JsonSerializer.Deserialize <MarketplaceQueryResponse>(responseBody); Console.Write("Query 1 sent. "); Console.WriteLine("Returned {0} items", response.results.Count); response.AddToMarketplaceList(items); int count = response.total_count; if (count > 100) { try { for (int pos = 100; pos <= count; pos += 100) { Console.WriteLine("({0}/{1})", pos, count); Thread.Sleep(Delay); query.AddParam("start", pos); Console.Write("Query {0} sent. ", pos / 100 + 1); items.AddRange(await ParsePage(query)); } } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0}", e.Message); Console.WriteLine("Saving {0} items", items.Count); } } return(items); }
public async static Task ParseToExcel(MarketplaceQuery query, bool open = false) { MarketplaceList list = await ParseTolist(query); ObjToExcel(list, open); }