Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from bs4 import BeautifulSoup
- # to get html, go to this link and copy the HTML from your browser inspect menu
- # https://store.steampowered.com/account/history/
- # then paste the contents in steam_purchases.html
- # read from file steam_purchases.html
- with open('steam_purchases.html', 'r', encoding='utf-8') as f:
- soup = BeautifulSoup(f, 'html.parser')
- rows = soup.find_all('tr', class_='wallet_table_row')
- rows = [r for r in rows if r.find('td', class_='wht_type').find('div').text == 'Purchase']
- row_details = []
- for row in rows:
- row_detail = {}
- row_detail['date'] = row.find('td', class_='wht_date').text
- try:
- row_detail['game'] = row.find('td', class_='wht_items').find('div').text.strip()
- except AttributeError:
- row_detail['game'] = row.find('td', class_='wht_items').text.strip()
- row_detail['amount'] = float(row.find('td', class_='wht_total').text.strip().replace('$', ''))
- row_details.append(row_detail)
- df = pd.DataFrame(row_details)
- print(f'Total spent on games: ${df["amount"].sum():,.2f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement