goldsmith / Wikipedia

A Pythonic wrapper for the Wikipedia API
https://wikipedia.readthedocs.org/
MIT License
2.88k stars 519 forks source link

The sections attribute is an empty list. #77

Open radicalbiscuit opened 9 years ago

radicalbiscuit commented 9 years ago

The example page, where I've noticed the issue: Comparison of MUTCD-Influenced Traffic Signs

Here's what's happening:

import wikipedia
mutcd = wikipedia.page('Comparison of MUTCD-Influenced Traffic Signs')
mutcd.sections

Which outputs [].

I would expect the section headers from the ToC to appear in the list as mentioned in the documentation. Let me know if I'm just doing it wrong!

makarandtapaswi commented 9 years ago

Hi I think this fixes it. Replace line 646 from wikipedia.py as follows:

query_params.update({'page': self.title})

Apparently the previous thing was essentially returning a dictionary {'titles': self.title} and titles was not a valid call in the API.

Here is an example -- http://en.wikipedia.org/w/api.php?action=parse&prop=sections&page=MATLAB

I'm going to make a pull request now.

lucas-tulio commented 9 years ago

@makarandtapaswi I checked your pull request and I believe the attr check was necessary. Other than that, I made the exact same change. Feel free to try another pull request with my code if you want.

foebu commented 9 years ago

Any news regarding this issue? Has it been fixed and it will be included in the next release? Do you know if there is any workaround for the actual release?

davidjmerritt commented 7 years ago

Is this fix going to be moved to the main branch?

nachogoro commented 7 years ago

It has been well over two years since this bug was reported and fixed by different people. This is a serious bug affecting the most basic uses of the API. Will any of the fixes be merged into master?

arjunkalburgi commented 6 years ago

@goldsmith can you please merge? :)

martin-majlis commented 6 years ago

I was facing the same issue. And since it's almost 3 years and it doesn't look, that it will get fixed, I have 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:

Differences between MUTCD-influenced traffic signs
Table of traffic signs comparison
See also
Notes
TrevorC85 commented 5 years ago

update on makarandtapaswi recommended changes. This still works but wikipedia.py line 646 shows:

query_params.update(self.__title_query_param) change to query_params.update({'page': self.title})