smartel99

steam_bot

Jul 5th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import requests
  2. import bs4
  3.  
  4.  
  5. def main():
  6.     search = input("What is the username that you want to search for?")
  7.  
  8.     html, url = get_html_from_web(search)
  9.  
  10.     username, account_value = get_info_from_html(html)
  11.  
  12.     if username == None and account_value == None:
  13.         print('There is no account named {}'.format(search))
  14.     else:
  15.         print("{}'s account is worth {}! Info collected from {}".format(
  16.             username.strip(),
  17.             account_value,
  18.             url
  19.         ))
  20.  
  21.  
  22. def get_html_from_web(search):
  23.     url = 'https://steamdb.info/calculator/?player={}&cc=ca'.format(search)
  24.     response = requests.get(url)
  25.     return response.text, url
  26.  
  27.  
  28. def get_info_from_html(html):
  29.     soup = bs4.BeautifulSoup(html, 'html.parser')
  30.     # usernameCss = 'h1.header-title a'
  31.     # accountValueCss = 'span.number-price-lowest'
  32.     try:
  33.         username = soup.find(class_='header-title').get_text()
  34.     except AttributeError:
  35.         return None, None
  36.  
  37.     try:
  38.         account_value = soup.find(class_='number-price-lowest').get_text()
  39.     except AttributeError:
  40.         return None, None
  41.  
  42.     return username, account_value
  43.  
  44.  
  45. if __name__ == "__main__":
  46.     main()
Advertisement
Add Comment
Please, Sign In to add comment