goldsmith / Wikipedia

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

Wrong Output #266

Open MS-Jahan opened 3 years ago

MS-Jahan commented 3 years ago

I tried this:

import wikipedia
print(wikipedia.search("Ubuntu"))

It gave me this:

/home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py:389: GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 389 of the file /home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py. To get rid of this warning, pass the additional argument 'features="html5lib"' to the BeautifulSoup constructor.

  lis = BeautifulSoup(html).find_all('li')
Traceback (most recent call last):
  File "/home/sjs/msg/fbchat/wiki.py", line 2, in <module>
    print(wikipedia.summary("Ubuntu"))
  File "/home/sjs/.local/lib/python3.9/site-packages/wikipedia/util.py", line 28, in __call__
    ret = self._cache[key] = self.fn(*args, **kwargs)
  File "/home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 231, in summary
    page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
  File "/home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 276, in page
    return WikipediaPage(title, redirect=redirect, preload=preload)
  File "/home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 299, in __init__
    self.__load(redirect=redirect, preload=preload)
  File "/home/sjs/.local/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 393, in __load
    raise DisambiguationError(getattr(self, 'title', page['title']), may_refer_to)
wikipedia.exceptions.DisambiguationError: "bantu" may refer to: 
Bantu languages
Bantu peoples
Bantu knots
Black Association for Nationalism Through Unity
Bantu (band)
Bantu (album)
Bantu FC
Bantu expansion
Bantustan

I installed this package from pip: pip install wikipedia Python Version: 3.9.1

What's wrong?

MS-Jahan commented 3 years ago

I've uninstalled wikipedia from pip and cloned this repo. The output is different this time but still getting errors.

Traceback (most recent call last):
  File "/home/sjs/msg/fbchat/wiki.py", line 2, in <module>
    print(wikipedia.summary("Ubuntu"))
  File "/home/sjs/msg/fbchat/wikipedia/util.py", line 28, in __call__
    ret = self._cache[key] = self.fn(*args, **kwargs)
  File "/home/sjs/msg/fbchat/wikipedia/wikipedia.py", line 231, in summary
    page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
  File "/home/sjs/msg/fbchat/wikipedia/wikipedia.py", line 276, in page
    return WikipediaPage(title, redirect=redirect, preload=preload)
  File "/home/sjs/msg/fbchat/wikipedia/wikipedia.py", line 299, in __init__
    self.__load(redirect=redirect, preload=preload)
  File "/home/sjs/msg/fbchat/wikipedia/wikipedia.py", line 393, in __load
    raise DisambiguationError(getattr(self, 'title', page['title']), may_refer_to)
wikipedia.exceptions.DisambiguationError: "bantu" may refer to: 
Bantu languages
Bantu peoples
Bantu knots
Black Association for Nationalism Through Unity
Bantu (band)
Bantu (album)
Bantu FC
Bantu expansion
Bantustan
Sgewux commented 3 years ago

Same bro :(

MS-Jahan commented 3 years ago

Same bro :(

I've started using pymediawiki. Try this out.

iamtheef commented 3 years ago

Also, "goat" returns results for boat and "sheep" returns results about "ship" xD

wlerin commented 3 years ago

See #279

TL;DR: add auto_suggest=False to search and summary and page calls (maybe others too).