googlesearch
googlesearch copied to clipboard
ModuleNotFoundError: No module named 'urllib2'
- google-search version: 1.0.2
- Python version: 3.7.5
- Operating System: Windows 10 64 Bits
Description
It's giving this error when i execute: ModuleNotFoundError: No module named 'urllib2'.
What I Did
I'm trying to execute this code that i got on the lib page on pypi.org.
from googlesearch.googlesearch import GoogleSearch
response = GoogleSearch().search("something")
for result in response.results:
print("Title: " + result.title)
print("Content: " + result.getText())
@tsukuuyomi
I had the same issue too and I only know the reason for the issue. Looking forward for the solution.
Reason for that is there's no package called urllib2 in python-3 version. It's only in python-2. Instead there's an equivalent which is urllib.request for it. I think the author should modify that in order to make it compatible for newer python version.
Please anyone help us in getting this issue resolved.
@shashank7596 just importing it as import urllib.request as urllib2
does not work either. :/
It gives me a weird 'list index out of range' error, presumably from the urllib.request.quote()
I am unsure of what causes the error, but just fixing the import does not seem to solve the issue.
I think there are a few changes I am missing.
this is still a problem it seems, tried the example on the module README
>>> from googlesearch.googlesearch import GoogleSearch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<HIDDENPATH>/site-packages/googlesearch/googlesearch.py", line 6, in <module>
import urllib2
ModuleNotFoundError: No module named 'urllib2'
>>> response = GoogleSearch().search("something")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'GoogleSearch' is not defined
>>> for result in response.results:
... print("Title: " + result.title)
... print("Content: " + result.getText())
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'response' is not defined
I am having the same issue, I peeked and found this line was the culprit.
totalText = soup.select(GoogleSearch.TOTAL_SELECTOR)[0].children.next().encode('utf-8')
Printing the soup object returns and empty list.
print(soup.select(GoogleSearch.TOTAL_SELECTOR)) # outputs []
I will dig more into it.