wpm2341_如何仅用12行Python构建910 wpm的键入Bot

wpm2341

先决条件

pip install selenium

程式码片段

# Importing required modules and initializing variablesfrom 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 ______________________________________

就这样

Selenium很好,但是用它构建一个很棒的项目绝非易事。 现在您知道了,只需一点点Google搜索,查看DOM了解技术 ,即可构建什么样的很酷的项目

感谢您阅读到这里😏

翻译自: https://hackernoon.com/980-wpm-typing-bot-with-python-just-using-12-lines-of-code-ig2qj326c

wpm2341

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值