Created
November 27, 2012 17:24
-
-
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()
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
# 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