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;
答案 0 :(得分:0)
urllib2
是一个Python 2库。如果你想继续使用Python 3,你应该使用urllib.request
库。它们实际上是相同的。
编辑:似乎googlesearch
包适用于Python 2.您可以使用virtualenv
来构建py2环境。要成功使用py3 print()
函数,您应该在脚本的开头添加此行:
from __future__ import print_function