How to Build a 910-wpm Typing Bot with Just 12 Lines of Python

Written by Rishabh | Published 2019/10/12
Tech Story Tags: python | automation | coding | latest-tech-stories | selenium | programming | typing-bot | how-to-build-a-typing-bot

TLDR How to Build a 910-wpm Typing Bot with Just 12 Lines of Python with just 12 lines of Python.7,018 reads. The project is based on the TypingCat.com. The Typingcat.com is a web-based web-swapping tool that lets users type the text content from the web.com on the focused screen. It is then used to send a text message to the user to type what is stored inside a string variable on a focused screen. The project was created with the help of Python's Pip and Selenium.via the TL;DR App

Prerequisites
pip install selenium
Code Snippet
# Importing required modules and initializing variables

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import re
string = ''
# ______________________________________

# Opening thetypingcat.com on firefox

firefox = webdriver.Firefox()
firefox.get('https://thetypingcat.com/typing-speed-test/1m')
# ______________________________________

# Using javascript to get the typing content from the website and storing value in "string" variable

for i in range(firefox.execute_script('return document.querySelectorAll(".line").length')):
	string += firefox.execute_script('return document.querySelectorAll(".line")['+str(i)+'].innerHTML')

string = re.sub(r'<[^>]*>','',string) #This line is just delete tags present inside string
# ______________________________________

# Selenium commands to type what is stored inside string variable on the focused screen

action = ActionChains(firefox)
action.send_keys(string)
action.perform()

# ______________________________________ END ______________________________________

That's All

Selenium is good but building a cool project from it is more than awesome. And now you know what kind of cool projects can be build through just a little bit of google search, viewing the DOM, and by understanding the technology.
Thanks for Reading till here  😏

Written by Rishabh | Hi, Go do something positive, like "following me". BYE!!!
Published by HackerNoon on 2019/10/12