from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from PIL import Image
import ddddocr
import time
driver = webdriver.Chrome()
option = webdriver.ChromeOptions()
option.add_experimental_option("detach", True)
option.add_argument('--ignore-certificate-errors')
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=option)
driver.get('https://xatu.168wangxiao.com/web/login?redirect=%2Fhome')
driver.maximize_window()
time.sleep(3)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[1]/div/div/input").send_keys("username")
driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[2]/div/div/input").send_keys("password")
while True:
try:
svgHeml=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[4]/div/div[2]/div')
location = svgHeml.location
size = svgHeml.size
x1 = location['x']
y1 = location['y']
x2 = location['x'] + size['width']
y2 = location['y'] + size['height']
print("左上角坐标: (x1, y1) = ({0}, {1})".format(x1, y1))
print("右上角坐标: (x2, y1) = ({0}, {1})".format(x2, y1))
print("左下角坐标: (x1, y2) = ({0}, {1})".format(x1, y2))
print("右下角坐标: (x2, y2) = ({0}, {1})".format(x2, y2))
screenshot_path = 'screenshot.png'
driver.save_screenshot(screenshot_path)
im = Image.open(screenshot_path)
region = im.crop((x1, y1, x2, y2))
cropped_path = 'result_screenshot.png'
region.save(cropped_path)
start = time.time()
ocr = ddddocr.DdddOcr(show_ad=False)
with open(cropped_path, 'rb') as f:
img = f.read()
result = ocr.classification(img)
print("识别结果:",result)
num = eval(result)
print(result)
print(num)
end = time.time()
print("耗时:%s 秒" % str(start-end))
driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[4]/div/div[1]/input").send_keys(5)
driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[5]/div/button").click()
except:
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div/form/div[4]/div/div[2]/div').click()
time.sleep(3)
|