【问题标题】:Unable to use search method from googlesearch module in google colab notebook无法在 google colab notebook 中使用 googlesearch 模块中的搜索方法
【发布时间】:2020-10-24 07:56:53
【问题描述】:
try: 
    from googlesearch import search 
    
except ImportError:  
    print("No module named 'google' found") 
urls = [] 
for j in search(str(query),tld="com",start=1, num=15, stop=15, pause=0):
        print(j) 
        urls.append(j)

我在本地 Jupyter Notebook 中使用了相同的代码。有用。但是在 google colab notebook 中执行时,它显示了以下错误。

NameError                                 Traceback (most recent call last)
<ipython-input-38-a97ca791b5a9> in <module>()
      4     print("No module named 'google' found")
      5 urls = []
----> 6 for j in google-search(str(query),tld="com",start=1, num=15, stop=15, pause=0):
      7         print(j)
      8         urls.append(j)

NameError: name 'search' is not defined

所有必需的模块都已正确安装。

!pip install rake-nltk
!pip install google-search
!pip install google
!pip install urllib
!pip install beautifulsoup4

【问题讨论】:

    标签: python jupyter-notebook google-colaboratory google-search python-module


    【解决方案1】:

    答案在这里:https://github.com/MarioVilas/googlesearch/issues/39

    问题与包之间的名称冲突有关。如果你只安装google 而不是google-search,它会起作用。

    !pip install google
    

    如果您已经安装了它们,请使用:

    !pip uninstall google-search
    !pip uninstall google
    !pip install google
    

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 2019-02-28
      • 2020-12-30
      • 2018-06-29
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2015-03-10
      相关资源
      最近更新 更多