Advertisement
Guest User

Get Total Amount Spent on Steam Games

a guest
Mar 17th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | Gaming | 0 0
  1. import pandas as pd
  2. from bs4 import BeautifulSoup
  3.  
  4. # to get html, go to this link and copy the HTML from your browser inspect menu
  5. # https://store.steampowered.com/account/history/
  6. # then paste the contents in steam_purchases.html
  7.  
  8. # read from file steam_purchases.html
  9. with open('steam_purchases.html', 'r', encoding='utf-8') as f:
  10.     soup = BeautifulSoup(f, 'html.parser')
  11.  
  12. rows = soup.find_all('tr', class_='wallet_table_row')
  13. rows = [r for r in rows if r.find('td', class_='wht_type').find('div').text == 'Purchase']
  14.  
  15. row_details = []
  16. for row in rows:
  17.     row_detail = {}
  18.     row_detail['date'] = row.find('td', class_='wht_date').text
  19.     try:
  20.         row_detail['game'] = row.find('td', class_='wht_items').find('div').text.strip()
  21.     except AttributeError:
  22.         row_detail['game'] = row.find('td', class_='wht_items').text.strip()
  23.     row_detail['amount'] = float(row.find('td', class_='wht_total').text.strip().replace('$', ''))
  24.     row_details.append(row_detail)
  25.  
  26. df = pd.DataFrame(row_details)
  27. print(f'Total spent on games: ${df["amount"].sum():,.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement