Search code examples
pythonsteam

how to read a list of keywords and put each one at the end of a url


ok, I am trying to make a program which tells the user what steam custom URLs are available from a list they submit but I have only recently started python so I only know a little, I have a working program which allows the user to enter a single keyword and it tells them if the URL is available but I want them to be able to enter a list of keywords and it checks each one of them and prints only the available ones any ideas on how I could do this

my code so far

#Steam Custom Url Checker
#Started 21/09/2017
#Finished


import requests

keyword = (input("\n Please enter a keyword "))

url = ("http://steamcommunity.com/id/")

r = requests.get(url + keyword)


if 'The specified profile could not be found.' in r.text:
    print("\n Avaiable Custom Urls")
print("\n", url + keyword)
else :
    print('\nSorry that one is taken')

Solution

  • url = ("http://steamcommunity.com/id/")
    
    #list having the keywords (made by splitting input with space as its delimiter) 
    keyword = input().split()
    
    #go through the keywords
    for key in keywords :
    
       #everything else is same logic
       r = requests.get(url + key)
    
       print("URL :", url+key)
       if 'The specified profile could not be found.' in r.text:
            print("This is available")
       else :
            print('\nSorry that one is taken')
    

    That should iterate through your list of keywords and everything else is same.