Example #1
0
def wirte_code(saveUrl):
	r = session.get("https://www.yiban.cn/captcha/index?" +
					(str(int(time.time()))))
	with open(saveUrl, 'wb') as f:
		f.write(r.content)
	captcha_test.automation(r'yanzhengma.jpg')
	code = CSDN_OCR.Recognise(r'transfered_image.png')
	# code = quote(code, safe=string.printable)
	return code
Example #2
0
def Login(AppID, Acc_num):
    '''
	登录模块
	:param AppID:输入要进入的轻应用ID
	:param Acc_num: 账号序号,必须大于等于 2
	:return:
	'''
    driver.get(Login_Url + str(AppID))  #拼接AppID并访问
    time.sleep(1)
    nicname, account, password = Xlsx_Read(Acc_num)
    Acc_Box = driver.find_element_by_id('account-txt')  #找到账号输入框
    Pwd_Box = driver.find_element_by_id('password-txt')  #找到密码输入框
    Acc_Box.send_keys(account)
    Pwd_Box.send_keys(password)
    Log_Buttom = driver.find_element_by_id('login-btn')  #点击登录
    Log_Buttom.click()
    #如果点击登录后没有跳转,则引入验证码模块
    Web_Url = Login_Url + str(AppID)
    Web_Title = driver.title
    if Web_Title == u"易班 - 登录":  #验证网页是否还在登录页
        Captcha_Buttom = driver.find_element_by_class_name('captcha')  #找到验证码图片
        # 截图或验证码图片保存地址
        screenImg = "./screenImg.png"
        Dead_Num = 1
        while True:
            Dead_Num = Dead_Num + 1  #防止死循环
            # 浏览器页面截屏
            driver.get_screenshot_as_file(screenImg)
            # 定位验证码位置及大小
            location = Captcha_Buttom.location
            size = Captcha_Buttom.size
            # 在网页截图的基础上重新裁切出来验证码
            left = location['x']
            top = location['y']
            right = location['x'] + size['width']
            bottom = location['y'] + size['height']
            #print(left+" "+right+" "+top+" "+bottom)
            # 从文件读取截图,截取验证码位置再次保存
            img = Image.open(screenImg).crop((left, top, right, bottom))
            img.save(screenImg)
            captcha_test.automation("screenImg.png")
            Ca_Text = CSDN_OCR.Recognise("transfered_image.png")
            Ca_Box = driver.find_element_by_id("login-captcha")
            Ca_Box.send_keys(Ca_Text)
            Log_Buttom.click()
            time.sleep(0.5)
            Web_Title = driver.title
            if Web_Title != u"易班 - 登录":
                print("登录成功")
                time.sleep(2)  # 等待两秒操作时间
                token = driver.get_cookie("yiban_user_token")
                token = token["yiban_user_token"]
                print(token)
                requests.post("https://q.yiban.cn/vote/insertBoxAjax",
                              data=Vote_Data,
                              cookies=token)
                print("投票成功!")
                time.sleep(1)
                driver.get("https://q.yiban.cn/logout")
                print("正在推出登录...")
                time.sleep(1)
                os.system("cls")
                driver.get(Login_Url + str(AppID))
                return 0  #中断函数
    elif Web_Title != u"易班 - 登录":
        print("登录成功")
        time.sleep(2)  # 等待两秒操作时间
        token = driver.get_cookie()
        token = token["yiban_user_token"]
        print(token)
        requests.post("https://q.yiban.cn/vote/insertBoxAjax",
                      data=Vote_Data,
                      cookies=token)
        print("投票成功!")
        time.sleep(1)
        driver.get("https://q.yiban.cn/logout")
        print("正在推出登录...")
        time.sleep(1)
        os.system("cls")
        driver.get(Login_Url + str(AppID))
        return 0