Wikipedia icon indicating copy to clipboard operation
Wikipedia copied to clipboard

Library not returning sections

Open mcat-ee opened this issue 8 years ago • 12 comments

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

mcat-ee avatar Apr 18 '16 12:04 mcat-ee

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.

image

mcat-ee avatar Apr 18 '16 12:04 mcat-ee

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

barrust avatar May 01 '16 06:05 barrust

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 avatar Apr 10 '18 08:04 anisayari

@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!

barrust avatar Apr 10 '18 11:04 barrust

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.)

anisayari avatar Apr 10 '18 13:04 anisayari

Can confirm @barrust fork of the libary fixes this sections issue

kaleidawave avatar May 19 '18 11:05 kaleidawave

hey @goldsmith - could you merge the pending PRs?

mcat-ee avatar Jul 07 '18 02:07 mcat-ee

Still no sections here

johann-lau avatar Jan 19 '21 06:01 johann-lau

@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

stedf avatar Feb 10 '22 07:02 stedf

pip3 install git+https://github.com/goldsmith/Wikipedia gives me an installation error

kanjurer avatar Jul 23 '24 05:07 kanjurer

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 ?

stedf avatar Jul 30 '24 10:07 stedf

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.

kanjurer avatar Jul 30 '24 15:07 kanjurer