Advertisement
Nicba1010

Masterpiece

Aug 17th, 2018
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. import json
  2.  
  3. import requests
  4. from bs4 import BeautifulSoup
  5.  
  6. total = 0
  7. for i in range(1, 75):
  8.     print("PAGE{}".format(i))
  9.     print("Current TOTAL: {}".format(total))
  10.     sup = BeautifulSoup(
  11.         requests.get("https://store.playstation.com/en-us/grid/STORE-MSF77008-PS3ALLPS3GAMES/{}?gameType=ps3_full_games%2Cminis%2Cps2_classics%2Cpsone_classics%2Cpsn_games%2Cdisc_only&platform=ps3".format(i)).content,
  12.         'lxml')
  13.     for x in sup.find_all('div', {'class': 'grid-cell__title '}):
  14.         y = None
  15.         while True:
  16.             try:
  17.                 print('https://store.playstation.com/valkyrie-api/en/us/999/resolve/{}?depth=999'.format(
  18.                     x.parent['href'].split('/')[-1]))
  19.                 y = json.loads(requests.get(
  20.                     'https://store.playstation.com/valkyrie-api/en/us/999/resolve/{}?depth=999'.format(
  21.                         x.parent['href'].split('/')[-1])).content)
  22.                 break
  23.             except Exception:
  24.                 pass
  25.         if type(y['included']) is list:
  26.             for inc in y['included']:
  27.                 try:
  28.                     if inc['attributes']['file-size']['value'] is not None:
  29.                         if inc['attributes']['file-size']['unit'] == 'MB':
  30.                             total += int(inc['attributes']['file-size']['value']) * 1024 * 1024
  31.                         elif inc['attributes']['file-size']['unit'] == 'GB':
  32.                             total += int(inc['attributes']['file-size']['value']) * 1024 * 1024 * 1024
  33.                         elif inc['attributes']['file-size']['unit'] == 'KB':
  34.                             total += int(inc['attributes']['file-size']['value']) * 1024
  35.                     print(
  36.                         "{} {}".format(inc['attributes']['file-size']['value'], inc['attributes']['file-size']['unit']))
  37.                 except KeyError:
  38.                     pass
  39.         else:
  40.             if y['included']['attributes']['file-size']['value'] is not None:
  41.                 if y['included']['attributes']['file-size']['unit'] == 'MB':
  42.                     total += int(y['included']['attributes']['file-size']['value']) * 1024 * 1024
  43.                 elif y['included']['attributes']['file-size']['unit'] == 'GB':
  44.                     total += int(y['included']['attributes']['file-size']['value']) * 1024 * 1024 * 1024
  45.                 elif y['included']['attributes']['file-size']['unit'] == 'KB':
  46.                     total += int(y['included']['attributes']['file-size']['value']) * 1024
  47.             print("{} {}".format(y['included']['attributes']['file-size']['value'],
  48.                                  y['included']['attributes']['file-size']['unit']))
  49.     print("Current TOTAL: {}".format(total))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement