Skip to content

Instantly share code, notes, and snippets.

@bdewilde
Created November 27, 2012 17:24
Show Gist options
  • Save bdewilde/4155663 to your computer and use it in GitHub Desktop.
Save bdewilde/4155663 to your computer and use it in GitHub Desktop.
Get list of X-men abilities, put it together with other methods in main()
# take parsed HTML for X-man's Wikipedia page
# return list of abilities
def get_xmen_abilities(soup):
infobox = soup.find('table', class_='infobox')
if infobox is not None :
abilities = infobox.find('th', text='Abilities')
if abilities is not None :
abilities_list = abilities.next_sibling.next_sibling.find_all(text=True)
abilities_list = [item.strip("\n") for item in abilities_list if item!='' and item!='\n']
return abilities_list
else : return []
if __name__ == '__main__':
xmen = get_xmen()
xmen_abilities = {}
for xman in xmen :
html = wikipedia_search(xman, xmen[xman])
abilities = get_xmen_abilities(html)
xmen_abilities[xman] = abilities
print "\n", xman, "\n", xmen_abilities[xman]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment