paint-brush
How to Build a 910-wpm Typing Bot with Just 12 Lines of Pythonby@Rishabh
7,647 reads
7,647 reads

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

by RishabhOctober 12th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

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.

Company Mentioned

Mention Thumbnail
featured image - How to Build a 910-wpm Typing Bot with Just 12 Lines of Python
Rishabh HackerNoon profile picture

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  😏