def get_abilities():
    """Visit Bulbapedia and pull names and descriptions from the table, 'list of Abilities.' Save as JSON."""
    page = requests.get('http://bulbapedia.bulbagarden.net/wiki/Ability')
    soup = bs4.BeautifulSoup(page.text)
    table = soup.find("table", {"class": "sortable"})
    tablerows = [tr for tr in table.children if tr != '\n'][1:]
    abilities = {}

    for tr in tablerows:
        cells = tr.find_all('td')
        ability_name = cells[1].get_text().strip().replace(' ', '-').lower()
        ability_desc = unicode(cells[2].get_text().strip())
        abilities[ability_name] = ability_desc

    srcpath = path.dirname(__file__)
    with io.open(path.join(srcpath, 'abilities.json'), 'w', encoding='utf-8') as f:
        f.write(json.dumps(abilities, ensure_ascii=False))
def get_abilities ( ) : page = requests . get ( 'http://bulbapedia.bulbagarden.net/wiki/Ability' ) soup = bs4 . BeautifulSoup ( page . text ) table = soup . find ( "table" , { "class" : "sortable" } ) tablerows = [ tr for tr in table . children if tr != '\n' ] [ 1 : ] abilities = { } for tr in tablerows : cells = tr . find_all ( 'td' ) ability_name = cells [ 1 ] . get_text ( ) . strip ( ) . replace ( ' ' , '-' ) . lower ( ) ability_desc = unicode ( cells [ 2 ] . get_text ( ) . strip ( ) ) abilities [ ability_name ] = ability_desc srcpath = path . dirname ( __file__ ) with io . open ( path . join ( srcpath , 'abilities.json' ) , 'w' , encoding = 'utf-8' ) as f : f . write ( json . dumps ( abilities , ensure_ascii = False ) )
Visit Bulbapedia and pull names and descriptions from the table, 'list of Abilities.' Save as JSON.