python https://admintuts.com/how-to-check-the-availability-of-a-steam-id-without-using-the-official-

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python https://admintuts.com/how-to-check-the-availability-of-a-steam-id-without-using-the-official-相关的知识,希望对你有一定的参考价值。

import requests # http://docs.python-requests.org/en/master/
from bs4 import BeautifulSoup # https://www.crummy.com/software/BeautifulSoup/

def check(name):
    """
    Function to check the availability of a specific Steam ID.
    """
    session = requests.Session() # Initilzes a new session object from the requests module
    matches = [] # Creates an empty list to hold our match objects
    requestUrl = "https://steamcommunity.com/id/%s" % name # Creates a variable to hold our request url which should be the url to the Steam profile page

    response = session.request("GET", requestUrl) # Makes an HTTP request to the profile page using the session we initialized above
    
    if response.status_code is 200: # Checks if the request was successful before trying to parse the response on the next line
        soup = BeautifulSoup(response.content, "html.parser") # Initializes our HTML parser module of choice, BeautifulSoup4, with the passed in response content

        # Available
        match1 = soup.body.findAll(text='The specified profile could not be found.') # Searches the page for the specified text and adds it to a variable
        # Taken
        match2 = soup.body.findAll(text='This profile is private.') # Searches the page for the specified text and adds it to a variable
        match3 = soup.find('div', attrs={'class': 'profile_header'}) # Searches the page for an element with the specified class name and adds it to a variable

        matches = [match1, match2, match3] # Adds all 3 of the above match variables to the list we created earlier
        if matches is not []: # Checks if that list is empty and if it is not empty, it executes the code indented below
            if matches[0]:
                print(name + " - AVAILABLE")
                return True
            elif matches[1] or matches[2]:
                print(name + " - IN USE")
                return False
        else: # Fallback in case our list is empty, just say the name is not available.
            print(name + " - NOT AVAILABLE")
            return False

以上是关于python https://admintuts.com/how-to-check-the-availability-of-a-steam-id-without-using-the-official-的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python