Last active
March 30, 2021 12:15
-
-
Save allanbatista/b798ed1100ff8e620a6fa9f1a7910357 to your computer and use it in GitHub Desktop.
Mercado Livre (MELI) - Download Categoria e Atributos
This file contains 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
import json | |
import requests | |
from tqdm import tqdm | |
categories = requests.get("https://api.mercadolibre.com/sites/MLB/categories/all").json() | |
def get_attributes(cat): | |
cat['attributes'] = requests.get(f'https://api.mercadolibre.com/categories/{cat["id"]}/attributes').json() | |
for subcat in cat.get('children_categories', []): | |
get_attributes(subcat) | |
for key, cat in tqdm(list(categories.items()), total=len(categories)): | |
get_attributes(cat) | |
with open("meli-categories-with-attributes.jsonl", "w+") as f: | |
for cat in categories.values(): | |
f.write(json.dumps(cat)+"\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment