Wikipedia
Wikipedia copied to clipboard
Library not returning sections
I've just installed the Wikipedia library and it's returning various other aspects of a page (e.g. summary, references) but not the sections. It doesn't even return None, it simply returns an empty list object.
Has this been encountered before?
My current code for replicating this error is as follows:
page = wikipedia.page("FN-6")
print page.sections
Okay, it seems that the library is accidentally parsing the 'Edit' part of a section heading as part of the heading.
See attached image for an example of this.
This has to do with the query parameters not being correct for when the page is title based. In a fork of this code base I fixed the issue (https://github.com/barrust/Wikipedia) since this one hasn't been updated in awhile. To fix it I changed:
query_params.update(self.__title_query_param)
to
if not getattr(self, 'title', None):
query_params['pageid'] = self.pageid
else:
query_params['page'] = self.title
I got a sililar issue with sections in python 3.6 : page.sections returning always an empty list.
import wikipedia
page = wikipedia.page(pageid=21055())
print(page.sections)
#[]
@anisayari This repo doesn't seem to be maintained any more. The empty sections is a common issue in the issues log (#77 #95 #168 #119) As such, about a year ago I wrote a re-write fork of this library (https://github.com/barrust/mediawiki) that aims to support multiple mediawiki sites and not just Wikipedia. Hope this helps!
Thank you @barrust , I am gonna take a look to your fork. (I hope this repo will be maintained, because it's a useful project.)
Can confirm @barrust fork of the libary fixes this sections issue
hey @goldsmith - could you merge the pending PRs?
Still no sections here
@johann-lau
as today if I use: pip3 install wikipedia sections still returns an empty list, while is possible to call the single sections by section name.
if i use: pip3 install git+https://github.com/goldsmith/Wikipedia everything seems to be working fine
pip3 install git+https://github.com/goldsmith/Wikipedia gives me an installation error
pip3 install git+https://github.com/goldsmith/Wikipedia gives me an installation error instead of giving thumbs down, why don't you share what error you get ?
pip3 install git+https://github.com/goldsmith/Wikipedia
Collecting git+https://github.com/goldsmith/Wikipedia
Cloning https://github.com/goldsmith/Wikipedia to c:\users\kanav\appdata\local\temp\pip-req-build-tfdd_w6k
Running command git clone --filter=blob:none --quiet https://github.com/goldsmith/Wikipedia 'C:\Users\kanav\AppData\Local\Temp\pip-req-build-tfdd_w6k'
Resolved https://github.com/goldsmith/Wikipedia to commit 1554943e8ab463cef5e93081def48fafbdef324e
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\kanav\AppData\Local\Temp\pip-req-build-tfdd_w6k\setup.py", line 19, in <module>
version = re.search(
AttributeError: 'NoneType' object has no attribute 'groups'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.