Steam wishlist scrapper

Hello, I am using steamtrades, and I faced an issue that I need to get steam wishlist as text. I create python script which gets all games from wishlist and print in terminal all games.

Ar first I need to install requests package.

pip install requests

Here is how wishlist API link looks like:

My wishlist contains more than 200 games. That’s why I have three pages p=0, p=1, p=2. Each page contains 100 games. Let’s start codding by importing packages, defining a function and variables.

import requests

def scrap_wishlist(steamid):
    page_number = 0
    games_list = []


I will need a while construction to loop through all available pages.

while True:
    page = requests.get(

    if len(page) < 2:

    games_list.extend(value['name'] for value in page.values())

    page_number += 1


I am looping through the wishlist pages and get output in json format. Then I am checking the length of the received output, and if length less then 2 I stop the loop. I am doing this in case of empty response from a page, this means there is no more game on a page but it this will the only issue logically will be check if len equal to 0. But here is the second issue, if the user enters not valid steam id output look like

{'success': 2}

To stop loop if steamid is not valid I checking if len < 2. Then I am looping through values of json pages and add names into game_list. And increase page_number value on 1. So next iteration of a loop will scrap next page from wishlist. 

As final step function return sorted a list.

return sorted(games_list)

And execute a function with correct steamid.

if __name__ == '__main__':
    # Replace steam id with real value
    for game in scrap_wishlist(12312312412):

Check the code on GitHub.