Wikipedia API for python

I am trying to see the table of contents on a wikipedia page using the Wikipedia API for python. Here is my code.

>>> import wikipedia >>> ny = wikipedia.page("New York") >>> ny.sections 

But I get an empty list [] as a result. When I go to the page and check, I see that there is content in the table of contents. Everything that is said in the documentation seems to work except this one. I am new to python coming from java background.

+8
wikipedia-api
source share
2 answers

There is an error in the current version of the python API Wikipedia library. You can install the lucasdnd branch on github that fixed this:

 pip install git+https://github.com/lucasdnd/Wikipedia.git 

(You can --upgrade if you already installed it)

Now:

 >>> import wikipedia >>> ny = wikipedia.page("New York") >>> ny.sections [u'History', u'16th century', u'17th century', u'18th century, the American Revolution, and statehood', u'19th century', u'Immigration', u'September 11, 2001 attacks', u'Hurricane Sandy, 2012', u'Geography', u'Climate', u'Statescape', u'Regions', u'Adjacent geographic entities', u'State parks', u'National parks', u'Administrative divisions', u'Demographics', u'Population', u'Most populous counties', u'Major cities', u'Metropolitan areas', u'Racial and ancestral makeup', u'Languages', u'Religion', u'LGBT', u'Economy', u'Wall Street', u'Silicon Alley', u'Microelectronic hardware and photographic processing', u'Media and entertainment', u'Tourism', u'Exports', u'Education', u'Transportation', u'Government and politics', u'Government', u'Capital punishment', u'Federal representation', u'Politics', u'Sports', u'See also', u'References', u'Further reading', u'External links'] 

Most likely, it will be fixed in the main library in the near future.

+9
source share

I ran into the same problem. And since it is almost 3 years old and does not look like it will be fixed, I created another simple library - Wikipedia-API .

 import wikipediaapi wiki = wikipediaapi.Wikipedia('en') mutcd = wiki.page('Comparison of MUTCD-Influenced Traffic Signs') print("\n".join([s.title for s in mutcd.sections])) 

Output:

 Places Media and entertainment Sports Ships Other uses See also 
+2
source share

All Articles