Google Search "Engine"

So I wrote this code a while ago, but I recently decided to update and “fix” it a bit. I might have gone a bit overboard, but anyway, it’s sort of like a Google search engine. It scrapes results from Google based on a given search term, etc.

from dataclasses import dataclass
from requests_html import HTMLSession
import urllib.parse

class SearchResult:
    rank: int
    url: str

class GoogleDomains:
    domains = (

class GoogleSearchEngine:
    def __init__(self):
        self.session = HTMLSession()

    def clear_google_links(cls, links):
        return list(filter(lambda url: not any(domain in url for domain in, links))

    def search(self, term):
        search_term = urllib.parse.quote_plus(term)
        search_url = f"{search_term}"

        response = self.session.get(search_url)
        links = list(response.html.absolute_links)
        links = self.clear_google_links(links)

        return [SearchResult(rank=i, url=result) for i, result in enumerate(links, start=1)]

class GoogleSearchApp:
    def run():
        print("Welcome to the Simple Google Search Engine!")
        google_search = GoogleSearchEngine()

        while True:
            print("1. Search")
            print("2. Credits")
            print("3. Quit")

            choice = input("Enter your choice: ")

            options = {
                "1": lambda:,
                "2": lambda: GoogleSearchApp.show_credits(),
                "3": lambda: GoogleSearchApp.quit(),

            if choice in options:

    def search(google_search):
        search_term = input("Enter your search term: ")
        search_results =

        if not search_results:
            print("No search results found.")
            print("\nSearch Results:")
            for result in search_results:
                print(f"{result.rank}. {result.url}")

    def show_credits():
        print("This Simple Google Search Engine was created by @sky.")
        print("Powered by requests-html.")

    def quit():

if __name__ == "__main__":

Isn’t it against Google’s ToS to scrape a Google website?

1 Like

It’s not scraping a site, it’s just scraping search results.