google-search urllib2错误

时间:2018-04-13 01:07:07

标签: python-3.5 urllib2 google-search

iam使用python 3.5和google-search模块但是当它在下面运行时它会给我错误

from googlesearch.googlesearch import GoogleSearch

response = GoogleSearch().search("anything")
for result in response.results:
    print("Title: " + result.title)
    print("Content: " + result.getText())

ERROR:

Traceback (most recent call last):
  File "C:/Users/xxx/Document/xxx/google_search.py", line 1, in <module>
   from googlesearch.googlesearch import GoogleSearch
  File "C:\Python35\lib\site-packages\googlesearch\googlesearch.py", line 6, in <module>
    import urllib2
ImportError: No module named 'urllib2

&#39;

1 个答案:

答案 0 :(得分:0)

urllib2是一个Python 2库。如果你想继续使用Python 3,你应该使用urllib.request库。它们实际上是相同的。

编辑:似乎googlesearch包适用于Python 2.您可以使用virtualenv来构建py2环境。要成功使用py3 print()函数,您应该在脚本的开头添加此行:

from __future__ import print_function