Googlesearch library does not work

Asked

Viewed 26 times

-2

I created a tool (python 3.7) a while ago using the library Googlesearch and worked normally, I decided to use it today and noticed that is giving problem in the library.

inserir a descrição da imagem aqui

Code:

from googlesearch import search

print(
    """

    banner     


    """
)

# Pegar tipo de conteúdo
print("Exemplos de conteúdo: Hacking, Forum, eBooks")
conteudo = str(input("Conteúdo:"))


# Dork para encontrar os URLS/LINKS/SITES
dork = f'{conteudo} site:onion.link | site:onion.cab | site:onion.sh | site:tor2web.fi | site:onion.direct'


# Menu de escolhas/seleção


def menu():
    banner = '''


    +-------------------------------------------------------+
    '''

    print(banner)

def escolha():
    print("0. Sair")
    print("1. Sites Onion")
    print("2. Créditos")


menu()

while True:
    escolha()
    menuzinho = int(input("Selecione uma opção: "))
    if menuzinho == 0:
        print("Até a proxima")
        break
    elif menuzinho == 1:
        with open("site.txt", "w") as stream:
            for url in search(dork, stop=50 or 1):
                print(url, file=stream)
            print("-----------------------------------------------------")
            print("Os links foram salvos no seguinte txt: site.txt")
            print("-----------------------------------------------------")
    elif menuzinho == 2:
        print("")
        print("Criado por")
        print("")
        input("Pressione ENTER para continuar")
    else:
        print("Essa opção não existe, tente novamente!")
  • you should, in the meantime, have created a file with the name "Googlesearch.py" in the same directory as your test program. Python then imports your file instead of the library.

  • How do I fix it?

  • change the name of the file named identical to the library name to another one. Otherwise, the search done by Python during the command import will always find this file first and skip the library.

  • However, it doesn’t seem to be your case - the error you pasted indicates that Python is taking the correct library file.

1 answer

0

You’re trying to use the library the wrong way - the call search is not a library function googlesearch, and yes, a class method GoogleSearch. This class yes, can be imported from the library.

This is easily observable in the short usage example on the library download page (https://pypi.org/project/google-search/):

from googlesearch.googlesearch import GoogleSearch

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

(observe: from googlesearch import GoogleSearch and not from googlesearch import search -- may even have worked someday, but if so, it was an earlier version of the library)

  • https://i.imgur.com/wNaCJWL.png

Browser other questions tagged

You are not signed in. Login or sign up in order to post.