Skip to content

Instantly share code, notes, and snippets.

@jrub
Created April 18, 2026 17:25
Show Gist options
  • Select an option

  • Save jrub/106958f23d850497c265e72ab19c3194 to your computer and use it in GitHub Desktop.

Select an option

Save jrub/106958f23d850497c265e72ab19c3194 to your computer and use it in GitHub Desktop.
Dumps the full Wallapop category tree to data/wallapop_categories.json
"""
fetch_wallapop_categories.py
Dumps the full Wallapop category tree to data/wallapop_categories.json
"""
import requests
import json
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'es-ES,es;q=0.9',
'Referer': 'https://es.wallapop.com/',
}
def walk(node, path):
current_path = path + [node['name']]
children = node.get('subcategories', [])
yield str(node['id']), {
'name': node['name'],
'path': current_path,
'leaf': not bool(children),
}
for child in children:
yield from walk(child, current_path)
r = requests.get('https://api.wallapop.com/api/v3/categories', headers=HEADERS, timeout=10)
tree = {}
for top in r.json()['categories']:
for cat_id, data in walk(top, []):
tree[cat_id] = data
with open('data/wallapop_categories.json', 'w', encoding='utf-8') as f:
json.dump(tree, f, indent=2, ensure_ascii=False)
print(f'Guardado: {len(tree)} categorías en data/wallapop_categories.json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment