connie_tong

导航

 

创建py文件

编写一个py文件,内容如下:

from selenium import webdriver
import time
from PIL import Image
from aip import AipOcr

# 识别验证码
def get_valiCode():
    app_id = str('')
    api_key = ''
    secret_key = ''

    client = AipOcr(app_id,api_key,secret_key)

    with open(r'./验证码截图.png','rb') as a:
        img = a.read()
        text=client.basicAccurate(img) 

    if text['words_result']:
        return text['words_result'][0]['words']
    else:
        return 'TEST'


browser = webdriver.Chrome()
time.sleep(1)
#browser = webdriver.Firefox()
L1 =[]
L2 =[]
L3 ={}
s = ''
exception_details_text = "<p>异常短信错误代號統計如下:<br/>"

#登錄界面
browser.get('https://')
#輸入賬號
browser.find_element_by_name("account").send_keys('')
#輸入密碼
browser.find_element_by_name("password").send_keys('')

# 识别验证码
browser.save_screenshot(r'./登录截图.png')
element = browser.find_element_by_id('imgObj')
        
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']

valicode = Image.open(r'./登录截图.png')
valicode = valicode.crop((left, top, right, bottom))
valicode.save(r'./验证码截图.png')

#val = raw_input(u"輸入驗證碼:")
#val = input("请输入驗證碼:")
#print u"輸入驗證碼:"
#val = raw_input()
#輸入驗證碼
browser.find_element_by_name("rand").send_keys(get_valiCode().replace(' ',''))
#登錄按鈕
browser.find_element_by_class_name("submit").click()

# 验证码不正确则重新输入
codeError = browser.find_elements_by_id("account.errors")
while len(codeError) != 0:
    #輸入賬號
    browser.find_element_by_name("account").send_keys('')
    #輸入密碼
    browser.find_element_by_name("password").send_keys('')

    # 识别验证码
    browser.save_screenshot(r'./登录截图.png')
    element = browser.find_element_by_id('imgObj')
            
    left = element.location['x']
    top = element.location['y']
    right = element.location['x'] + element.size['width']
    bottom = element.location['y'] + element.size['height']

    valicode = Image.open(r'./登录截图.png')
    valicode = valicode.crop((left, top, right, bottom))
    valicode.save(r'./验证码截图.png')

    #輸入驗證碼
    browser.find_element_by_name("rand").send_keys(get_valiCode().replace(' ',''))
    #登錄按鈕
    browser.find_element_by_class_name("submit").click()
    codeError = browser.find_elements_by_id("account.errors")

#點擊短訊傳送
browser.find_element_by_class_name("dxcs").click()

browser.maximize_window()

browser.find_element_by_id("btnSubmit").click()
time.sleep(10)


browser.find_element_by_xpath('//span[text()="短訊發送"]').click()
time.sleep(3)
browser.find_element_by_id('toPhoneNumber').send_keys('')
time.sleep(3)
today = time.time()
number = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(today))
browser.find_element_by_id('message').send_keys('测试短信'+number)
time.sleep(3)
browser.find_element_by_id('batch_content_yes').click()
time.sleep(3)
browser.find_element_by_xpath('//span[text()="確定"]').click()
time.sleep(10)

browser.find_element_by_id('toPhoneNumber').send_keys('')
time.sleep(3)
today = time.time()
number = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(today))
browser.find_element_by_id('message').send_keys('测试短信'+number)
time.sleep(3)
browser.find_element_by_id('batch_content_yes').click()
time.sleep(3)
browser.find_element_by_xpath('//span[text()="確定"]').click()
time.sleep(10)

browser.find_element_by_class_name("dxcs").click()

browser.find_element_by_id("btnSubmit").click()

time.sleep(15)

browser.save_screenshot('.\\printscreen.png')

browser.quit()

  

创建一个bat文件

test.py

  

 

 

在任务计划程序创建一个任务

 

 

 

 

 

 

成功

 

posted on 2021-05-22 16:04  connie_tong  阅读(219)  评论(0编辑  收藏  举报