好吧,我正在尝试制作一个程序,告诉用户可以从他们提交的列表中获取哪些 Steam 自定义 URL,但我最近才开始使用 python,所以我只知道一点,我有一个工作程序,允许用户输入单个关键字,它会告诉他们该 URL 是否可用,但我希望他们能够输入关键字列表,它会检查每个关键字并仅打印可用的关键字关于如何执行此操作的任何想法
到目前为止我的代码
#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')
最佳答案
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')
这应该遍历您的关键字列表,其他所有内容都是相同的。
关于python - 如何读取关键字列表并将每个关键字放在网址末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46371278/