Skip to content

Wiki disambiguation list issue #2

Description

@GregMcLindon

Debug results with "New York"... page_titles[1] returns 'New York, New York (disambiguation)' which generates internal server error:
page_titles = {list} <class 'list'>: ['New York', 'New York, New York (disambiguation)', 'New York (state)', 'New York City', 'Gangs of New York', 'New York-New York Hotel and Casino', 'Administrative divisions of New York (state)', 'Pastrami', 'New York Yankees', 'New York me
search_term = {str} 'new york'
title = {str} 'New York, New York (disambiguation)'


suggest adding check for '(disambigutation)':

def get_page(search_term):
warnings.filterwarnings("ignore") # disambiguations options triggers a user warning about parsing html
try:
page = wikipedia.page(search_term)
except wikipedia.exceptions.PageError:
# no such page, return a random one
page = wikipedia.page(wikipedia.random())
except wikipedia.exceptions.DisambiguationError:
# this is a disambiguation page, get the first real page (close enough)
page_titles = wikipedia.search(search_term)
# sometimes the next page has the same name (different caps), so don't try the same again
if page_titles[1].lower() == page_titles[0].lower() or page_titles[1].lower().find('(disambiguation)') > 0:
title = page_titles[2]
else:
title = page_titles[1]
page = get_page(wikipedia.page(title))
return page

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions