Last active
July 15, 2016 17:35
-
-
Save ayancey/c605760194984bf3443c to your computer and use it in GitHub Desktop.
For Joe
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 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