Last active
November 25, 2020 00:00
-
-
Save oliveira-andre/d78fe8e16cf62605f71aa1286b1c05a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import requests | |
| import json | |
| from bs4 import BeautifulSoup | |
| def template_html(): | |
| url = 'https://www.nuuvem.com/catalog/price/promo/sort/bestselling/sort-mode/desc'; | |
| response = requests.get(url); | |
| return BeautifulSoup(response.text, 'html.parser'); | |
| def main(): | |
| try: | |
| games = []; | |
| cards = template_html().find_all('a', 'product-card--wrapper'); | |
| for card in cards: | |
| title = card['title'] if card['title'] else '' | |
| price_str_obj = card.find_all('div', 'product-price')[0]['data-price']; | |
| price_obj = json.loads(price_str_obj) if price_str_obj else '' | |
| price = 'R$ {real},{cents}'.format(real=price_obj['iv'], cents=price_obj['c']) if price_obj != '' else '' | |
| game = { 'title': title, 'price': price }; | |
| games.append(game); | |
| print(json.dumps(games, indent = 3)); | |
| except: | |
| print('exception'); | |
| main(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment