zoukankan      html  css  js  c++  java
  • 6.12306模拟登陆.py

    from selenium import webdriver
    from time import sleep
    from PIL import Image
    from selenium.webdriver import ActionChains
    from Cjy import Chaojiying_Client
    from selenium.webdriver import ActionChains

    bro = webdriver.Chrome(executable_path='chromedriver.exe')
    bro.get('https://kyfw.12306.cn/otn/login/init')
    sleep(5)
    bro.save_screenshot('main.png')

    code_img_tag = bro.find_element_by_xpath('//*[@id="loginForm"]/div/ul[2]/li[4]/div/div/div[3]/img')
    location = code_img_tag.location
    size = code_img_tag.size
    # 裁剪的区域范围
    rangle = (
    int(location['x']), int(location['y']), int(location['x'] + size['width']), int(location['y'] + size['height']))

    i = Image.open('./main.png')
    frame = i.crop(rangle)
    frame.save('code.png')


    def get_text(imgPath, imgType):
    chaojiying = Chaojiying_Client('17338132275', '17338132275', '903523')
    im = open(imgPath, 'rb').read()
    return chaojiying.PostPic(im, imgType)['pic_str']


    # 55,70|267,133 ==[[55,70],[33,66]]
    result = get_text('./code.png', 9004)
    all_list = []
    if '|' in result:
    list_1 = result.split('|')
    count_1 = len(list_1)
    for i in range(count_1):
    xy_list = []
    x = int(list_1[i].split(',')[0])
    y = int(list_1[i].split(',')[1])
    xy_list.append(x)
    xy_list.append(y)
    all_list.append(xy_list)
    else:
    x = int(result.split(',')[0])
    y = int(result.split(',')[1])
    xy_list = []
    xy_list.append(x)
    xy_list.append(y)
    all_list.append(xy_list)
    print(all_list)
    # action = ActionChains(bro)
    for a in all_list:
    x = a[0]
    y = a[1]
    ActionChains(bro).move_to_element_with_offset(code_img_tag, x, y).click().perform()
    sleep(1)

    bro.find_element_by_id('username').send_keys('1320685524@qq.com')
    sleep(1)
    bro.find_element_by_id('password').send_keys('990496256dd')
    sleep(1)
    bro.find_element_by_id('loginSub').click()

    sleep(5)
    bro.quit()
  • 相关阅读:
    IOS开发中针对UIImageView的几种常用手势
    VIew中的触摸事件 touchBegin 等一系列方法
    控制器的跳转-modal与push
    终于决定把自己的小窝从CSDN搬到博客园了
    UIView的frame和bounds区别
    android中数据存储的contentprovider的使用方法
    android中Json数据保存方式
    android手机操作SD的使用方法
    android手机中图片的拖拉及浏览功能
    android图片切换ImageSwichter的动画切换效果
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12336692.html
Copyright © 2011-2022 走看看