anthonyhseb / googlesearch

Python library for scraping google search results
MIT License
115 stars 43 forks source link

Urllib2 causing troubles #6

Open Michael-E-Rose opened 6 years ago

Michael-E-Rose commented 6 years ago

I just installed google-search from PyPi for Python3.5. Importing the library causes an ImportError: No module named 'urllib2'. I think the package needs some update in this regard, this might help.

merose@Panther:~$ sudo -H pip3 install --upgrade google-search
Collecting google-search
Collecting lxml (from google-search)
  Downloading lxml-4.1.0-cp35-cp35m-manylinux1_x86_64.whl (5.5MB)
    100% |████████████████████████████████| 5.6MB 239kB/s 
Requirement already up-to-date: beautifulsoup4 in /usr/local/lib/python3.5/dist-packages (from google-search)
Installing collected packages: lxml, google-search
  Found existing installation: lxml 3.5.0
    Uninstalling lxml-3.5.0:
      Successfully uninstalled lxml-3.5.0
Successfully installed google-search-1.0.2 lxml-4.1.0
merose@Panther:~$ python3
Python 3.5.2 (default, Sep 14 2017, 22:51:06) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from googlesearch.googlesearch import GoogleSearch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/googlesearch/googlesearch.py", line 6, in <module>
    import urllib2
ImportError: No module named 'urllib2'
anthonyhseb commented 6 years ago

Hello Michael,

Thank's for reporting. This has been already discussed in Issue #4. But since that issue is more about language, I'll use this one for feedback on Python 3 compatibility.

As of now, google-search only supports Python 2. My next update on this library will probably address Python 3 compatibility. If you do feel like contributing, check out this pull-request that I have received which fixes Python 3 but breaks Python 2 compatibility.

I'll immediately review an pull any requests that build and succeed the tests.

alecbalec commented 6 years ago

Try changing to: import urllib

urllib.request for opening and reading URLs urllib.error containing the exceptions raised by urllib.request urllib.parse for parsing URLs urllib.robotparser for parsing robots.txt files

so changing to urllib.request

sripirakas commented 6 years ago

Hi Please have a look at my updated code which is compatible with Python 3.x versions. url: https://github.com/sripirakas/GoogleSearch/blob/master/googlesearch.py

Michael-E-Rose commented 6 years ago

Your code seems to work but I still can't import the module on my computer. Or was this not intended?