如何读取关键字的列表,并把每个关键字的末尾
问题描述:
好吧,我想做一个程序,告诉用户什么蒸汽自定义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')
这应该迭代你的关键字列表,其他的都是一样的。
答
import requests
keywords = (raw_input("\n Please enter a list keyword "))
available_keywords =[]
for keyword in keywords.split():
url = ("http://steamcommunity.com/id/")
r = requests.get(url + keyword)
if 'The specified profile could not be found.' in r.text:
available_keywords.append(url+keyword)
if len(available_keywords) >0:
print("List of available_keywords : ")
for url in available_keywords:
print (url)
else:
print ("Sorry no url is abailable")
答
import requests
keyword = (input("\n Please enter the keywords "))
keywords = keyword.split(" ")
url = ("http://steamcommunity.com/id/")
avai = list()
for key in keywords:
r = requests.get(url + key)
if 'The specified profile could not be found.' in r.text:
avai.append(key)
if len(avai)>0:
print("\n Avaiable Custom Urls")
for k in avai:
print("\n", url + k)
else :
print('\nSorry no url available')