Check out Kite (free AI Coding Assistant) → Link



Buy Me a Coffee? Your support is much appreciated!

Source Code:  

 

import os
from selenium import webdriver
from bs4 import BeautifulSoup
import pyautogui

def run_monkey_type():
    url = 'https://monkeytype.com/'
    driver_path = './Drivers/{0}'.format('geckodriver.exe')
    browser = webdriver.Firefox(executable_path=driver_path)
    browser.get(url)
    # browser.fullscreen_window()

    element_words = browser.find_element_by_id('words')
    soup = BeautifulSoup(element_words.get_attribute('innerHTML'), 'html.parser')
    words = soup.find_all('div', 'word')
    text_block = [word.text for word in words]
    text_block = ' '.join(text_block)

    keep_going = True
    while keep_going:
        try:      
            pyautogui.moveTo(800, 1000)
            pyautogui.click()
            pyautogui.click()
            pyautogui.write(text_block, interval=0)
            old_text_block = text_block
            search_string = old_text_block[-10:]

            element_words = browser.find_element_by_id('words')
            soup = BeautifulSoup(element_words.get_attribute('innerHTML'), 'html.parser')
            words = soup.find_all('div', 'word')
            text_block = ' '.join([word.text for word in words])
            text_block = text_block[text_block.index(search_string):].replace(search_string, '')

        except Exception as e:
            print(e)
            keep_going = False

run_monkey_type()