代码之家  ›  专栏  ›  技术社区  ›  xnx

如何读取关键字列表并将每个关键字放在url的末尾

  •  1
  • xnx  · 技术社区  · 7 年前

    好的,我正在尝试制作一个程序,告诉用户从他们提交的列表中可以获得哪些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')
    
    3 回复  |  直到 7 年前
        1
  •  2
  •   Kaushik NP    7 年前
    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')
    

    这应该遍历你的关键字列表,其他一切都是一样的。

        2
  •  0
  •   sourabh1024    7 年前
    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")
    
        3
  •  0
  •   im_w0lf    7 年前
    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')