我正在尝试创建一个不和谐的机器人,但运行下面的代码时无法从 googlesearch 导入搜索
import discord
import sys
import discord
from googlesearch import search
client = discord.Client()
ModeFlag = 0
@client.event
async def on_ready():
print('join')
@client.event
async def on_message(message):
global ModeFlag
if message.author.bot:
return
if message.content == '!exit':
await message.channel.send('ノシ')
sys.exit()
if ModeFlag == 1:
kensaku = message.content
ModeFlag = 0
count = 0
for url in search(kensaku, lang="jp",num = 5):
await message.channel.send(url)
count += 1
if(count == 5):
break
if message.content == '!google':
ModeFlag = 1
await message.channel.send('検索するワードをチャットで発言してね')
if message.content == 'bot君いる?':
client.run('***')
我收到此错误
导入“googlesearch”无法解决
这是我安装软件包
google
、discord
和 googlesearch
的方法。
pip install google & pip install discord & pip install googlesearch-python
我该怎么办?
我只是尝试安装并导入软件包
googlesearch-python
,它工作正常,没有任何问题。因此,我猜您的问题可能是由于您安装的 pip
版本造成的。如果您使用 python3
,请确保 pip
与 pip3
类似,否则您应该使用 pip3
以确保安全。
pip3 install google & pip3 install discord & pip3 install googlesearch-python
这是我所做的:
$ pip3 install googlesearch-python
$ python3
>>> from googlesearch import search
>>> search("Google")
['https://www.google.com/', 'https://twitter.com/Google?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor', 'https://blog.google/', 'https://about.google/intl/en_us/products/', 'https://about.google/', 'https://en.wikipedia.org/wiki/Google', 'https://www.facebook.com/Google/', '/search?q=Google&num=11&hl=en&tbm=isch&source=iu&ictx=1&fir=mM5eejaz-bUIsM%252C0UCf55-GTy6fDM%252C%252Fm%252F045c7b&vet=1&usg=AI4_-kS3fhB6I4-4YGkbI-0POxk60cjoEw&sa=X&ved=2ahUKEwi78Zfo3o3vAhXtwzgGHaFuBJYQ_B16BAhSEAI#imgrc=mM5eejaz-bUIsM']
从 googlesearch 导入搜索
query =“jampier Hilario risco García” 对于搜索结果(查询,tld =“com”,num = 10): 打印(结果)