Skip to content

Instantly share code, notes, and snippets.

@ahmedbesbes
Created January 20, 2020 13:28
Show Gist options
  • Save ahmedbesbes/aeee8a10c4a43c7d0c05b0683aef3d48 to your computer and use it in GitHub Desktop.
Save ahmedbesbes/aeee8a10c4a43c7d0c05b0683aef3d48 to your computer and use it in GitHub Desktop.
data = {}
soup = get_soup(base_url + '/categories')
for category in soup.findAll('div', {'class': 'category-object'}):
name = category.find('h3', {'class': 'sub-category__header'}).text
name = name.strip()
data[name] = {}
sub_categories = category.find('div', {'class': 'sub-category-list'})
for sub_category in sub_categories.findAll('div', {'class': 'child-category'}):
sub_category_name = sub_category.find('a', {'class': 'sub-category-item'}).text
sub_category_uri = sub_category.find('a', {'class': 'sub-category-item'})['href']
data[name][sub_category_name] = sub_category_uri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment