Skip to content

Instantly share code, notes, and snippets.

@ayancey
Last active July 15, 2016 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayancey/c605760194984bf3443c to your computer and use it in GitHub Desktop.
Save ayancey/c605760194984bf3443c to your computer and use it in GitHub Desktop.
For Joe
import requests
from bs4 import BeautifulSoup
import re
import json
import clipboard
first_level_categories = {74: {}, 75: {}, 134: {}, 79: {}, 53: {}, 86: {}, 110: {}, 76: {}, 77: {}}
# Get 2nd level categories
for category in first_level_categories:
r = requests.get('http://www.beertutor.com/beers/index.php?t=sub_pages&cat=' + str(category))
all_categories = re.findall('t=sub_pages&cat=.*"',r.text)
category_ids = []
for c in all_categories:
category_ids.append(int(c.split('&cat=')[1].split('"')[0]))
if category_ids:
if category_ids[0] == category:
if len(category_ids) == 1:
print 'No subcategories'
# Skip it
continue
for c in category_ids:
first_level_categories[category][c] = []
print first_level_categories
clipboard.copy(json.dumps(first_level_categories))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment