googlesearch icon indicating copy to clipboard operation
googlesearch copied to clipboard

ModuleNotFoundError: No module named 'urllib2'

Open malandrageboy opened this issue 5 years ago • 4 comments

  • 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())

malandrageboy avatar Dec 19 '19 01:12 malandrageboy

@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 avatar Jan 22 '20 16:01 shashank7596

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

Viole-Grace avatar Mar 12 '20 07:03 Viole-Grace

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

ghost avatar May 08 '20 16:05 ghost

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.

Alicia426 avatar Dec 08 '20 23:12 Alicia426