Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm attempting to see the list of contents in a Wikipedia page utilizing Wikipedia API for python. Here is my code.

>>> import wikipedia

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

>>> ny.sections

Be that as it may, I'm getting an empty list [] as the outcome. At the point when I go to the page and check, I can see that there is content in the chapter by chapter guide. The wide range of various things said in the documentation appear to work with the exception of this. I'm new to python coming from a java foundation.

1 Answer

0 votes
by (26.4k points)

There is a bug in the current rendition of the Wikipedia API python library. You can introduce a branch by lucasdnd on Github that fixed this: 

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

(You can --upgrade in the event that you as of now have it installed) 

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'] 

It'll ideally be fixed in the fundamental library in the near future.

Want to become a expert in Python? Join the python course fast!

For more details, do check out the below video tutorial...

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...