In order not to copy and write ** Do not use unexplained code ** I am writing the code in my heart. Therefore, I try to put a lot of comments in the program.
Automation by a famous typing game. (I will refrain from the title because there are terms of use.)
windows python3.6 anaconda3
from selenium import webdriver
from time import sleep
import time
from selenium.webdriver.common.action_chains import ActionChains #Needed to act
import pyautogui as pa
import pyocr
import pyocr.builders
import cv2
from PIL import Image
#driver open#
driver = webdriver.Chrome()
#window size#
driver.set_window_size(800, 800)
#Open site#
driver.get("http://hogehoge")
#Wait until the site opens#
sleep(10)
#Start button coordinates#
#>>> pyautogui.position()#
'''
start_x = 400
start_y = 523
'''
#Click the start button#
pa.click(400, 523)
sleep(3)
#Course click#
pa.click(400, 523)
sleep(3)
pa.press(" ")
sleep(3)
i = 0
while True:
    if i > 350:
        break
    print(i)
    #screenshot#
    pa.screenshot(imageFilename="sumple.png ", region=(282, 498, 200, 20))
    im = cv2.imread('sumple.png')#Image loading
    gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)#grayscale
    #Binarization
    im_gray = cv2.imread('sumple.png', 0)#Read as grayscale
    threshold_val = 100
    ret, thres_im = cv2.threshold(im_gray, threshold_val, 255,cv2.THRESH_BINARY)#Binarization
    cv2.imwrite('sumple.png', thres_im)#Binarized image storage
    im_bw = Image.open('sumple.png')
    #Character recognition#
    tool = pyocr.get_available_tools()[0]
    text = tool.image_to_string(im_bw, lang='eng', builder=pyocr.builders.TextBuilder())
    #Character input#
    print(text)
    pa.typewrite(text, interval = 0.1)
    i += 1
#End#
input("Enter something")
driver.close()
driver.quit()
It was my first code, so it took me a long time to check each one. I will continue to output even small things.
Recommended Posts