Skip to content

Instantly share code, notes, and snippets.

@avelardi
Created January 17, 2025 06:21
Show Gist options
  • Save avelardi/f32b4d7b174a404222327a5aed1c8da1 to your computer and use it in GitHub Desktop.
Save avelardi/f32b4d7b174a404222327a5aed1c8da1 to your computer and use it in GitHub Desktop.
simple xbox wishlist csv file export
import requests
from bs4 import BeautifulSoup
from pprint import pprint
from datetime import datetime
import string
d = {}
gc = 0
printable = set(string.printable)
#csv header row
p = 'game_name,url\n'
#output filename
fn = 'xbox_wishlist'
#wishlist url
#note: go to https://www.xbox.com/en-us/wishlist and click share to enable sharing and get the link
url = 'https://www.xbox.com/en-US/wishlist/61B9BD1E095854D22BA6C73FBC20B56498EDD77C92AFC861758CBA90718732550'
print('-----START: '+str(datetime.now().isoformat())+'-----')
r = requests.get(url)
s = BeautifulSoup(r.content,'html.parser')
for l in s.find_all('a'):
if 'class' in l.attrs:
if [x for x in l.attrs['class'] if 'wishlistProductItem' in x]:
try:
u = l.attrs['href'].split('?')[0]
except:
u = l.attrs['href']
n = ''.join(filter(lambda x: x in printable, l.attrs['aria-label']))
d[str(n)] = str(u)
gc+=1
print('Game count: {}'.format(str(gc)))
#pprint(d)
#fn = str(datetime.now().isoformat()).replace(':','.') + '.' + fn
if fn[-3:] != 'csv':
fn = fn+'.csv'
c = p
with open(fn,'w') as f:
f.write(p)
for i in d:
p = '{},{}\n'.format(i,d[i])
f.write(p)
c = c + p
#uncomment to have the csv content printed
#print(c)
print('Done!')
print('-----END: '+str(datetime.now().isoformat())+'-----' )
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment