Google验证码打码

Google验证码_打码

import time
import requests
from datetime import datetime
from selenium import webdriver


def valid_date(timestr):
    nowTime_str = datetime.now().strftime('%Y-%m-%d')
    # mktime参数为struc_time,将日期转化为秒,
    e_time = time.mktime(time.strptime(nowTime_str, "%Y-%m-%d"))
    # print(e_time)
    try:
        s_time = time.mktime(time.strptime(timestr, '%Y-%m-%d'))
        # print(s_time)
        # 日期转化为int比较
        diff = int(s_time) - int(e_time)
        # print(diff)
        if diff >= 0:
            is_true = True
            # print('True')
            return is_true
        else:
            is_true = False
            # self.show_data.emit('测试版本已不能试用!!!')
            # print('测试版本已不能试用!!!')
            print('False')
            return is_true
    except Exception as e:
        print(e)
        return 0


class SeleniumTest(object):
    """用来测试selenium相关脚本"""

    def __init__(self):
        self.url = "https://www.ispfsb.com/Public/FOID.aspx"
        self.__options = webdriver.ChromeOptions()
        self.__options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
        self.driver = webdriver.Chrome(options=self.__options)
        self.driver.maximize_window()

    @staticmethod
    def verify(response):
        url = "https://www.ispfsb.com/Reg/signup.aspx"
        data = {"g-recaptcha-response": response}
        response = requests.post(url, data=data)
        if response.status_code == 200:
            return response.text

    @staticmethod
    def create_task():
        url = 'http://api.recaptcha.press/task/create?siteKey=6LdAHv8UAAAAAC-KuK02qHMG7nLPZ3WpxZs7eG6K&siteReferer=https://www.ispfsb.com/&authorization=0a389ac1-ab1a-4d60-a089-1f182bd12461'

        try:
            response = requests.get(url)
            if response.status_code == 200:
                data = response.json()
                print('response data:', data)
                return data.get('data', {}).get('taskId')
        except requests.RequestException as e:
            print('create task failed', e)

    @staticmethod
    def polling_task(task_id):
        url2 = 'https://api.recaptcha.press/task/status?taskId=%s' % task_id
        count = 0
        while count < 60:
            try:
                response = requests.get(url2)
                if response.status_code == 200:
                    data = response.json()
                    print('polling result', data)
                    status = data.get('data', {}).get('status')
                    print('status of task', status)
                    if status == 'Success':
                        return data.get('data', {}).get('response')
            except requests.RequestException as e:
                print('polling task failed', e)
            finally:
                count += 1
                time.sleep(3)

    def get_data(self):
        """请求页面"""
        self.driver.get(self.url)
        time.sleep(3)
        self.driver.execute_script(
            """document.querySelector("#divStep1 > div:nth-child(2) > div > span > a").click();""")
        # time.sleep(3)
        input("信息填完后按回车:")
        task_id = self.create_task()
        task_id = self.polling_task(task_id)
        print("task_id:", task_id)
        js_code = 'document.getElementById("g-recaptcha-response").innerHTML="{}";'.format(task_id)
        print(js_code)
        self.driver.execute_script(js_code)


if __name__ == "__main__":
    is_true = valid_date("2021-09-10")
    if is_true:
        st = SeleniumTest()
        while True:
            st.get_data()

    else:
        print('测试到期!!!')

posted @ 2023-02-25 13:06  Victor's  阅读(52)  评论(0)    收藏  举报
友链: 嘿嘿嘿...

   本站总访问量: