【科学家养成日记#7】Zapper每日打卡自动化

in hive-180932 •  3 years ago 

Zapper有每日打卡获得积分的任务。之前研究过写代码自动化打卡,但是最后被google验证给难住了。虽然可以用第三方的打码平台来解决google验证,但是成本会高,所以就放弃了自动化zapper打卡的计划

前几天看到一篇用Selenium自动化模拟zapper的文章:https://mirror.xyz/gashub.eth/3Aa9h_zEgho58nRn4PAswd-X1c3XBty3nlWJNrM3k5Y

虽然写的不是zapper打卡,但是流程差不多,所以稍微改了一下。源代码是Python:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

def findHub(driver,element,by=By.XPATH,timeout=5,times = 1):
    '''
    element为选择器表达式
    timeout为要素寻找超时时间,默认5秒
    times为寻找次数,默认3次
    by 可选参数
    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"
    '''
    try:
        ele = WebDriverWait(driver, timeout).until(
            EC.presence_of_element_located((by, element))
        )
        ele.click()
        time.sleep(3)
        return True
    except Exception as e:
        if times != 0:
            print("找不到要素",element, "。重试第", times, "次。")
            result = findHub(driver, element, by, timeout, times - 1)
        else :
            return False
        return result


def unlockWallet(driver, password):
    driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/popup.html")
    time.sleep(5)
    driver.find_element_by_id('password').send_keys(password)
    findHub(driver, 'button', By.TAG_NAME)

def claim(account):
    # 小狐狸钱包解锁密码
    password = ''
    # 浏览器驱动目录
    driverPath = r'D:\bin\chromedriver'
    # 浏览器缓存数据,包括收藏夹,扩展,记录的密码,cookies等
    userDataPath = r'user-data-dir=D:\bin\\'+account
    options = webdriver.ChromeOptions()
    options.add_argument(userDataPath)
    driver = webdriver.Chrome(executable_path=driverPath, options=options)
    unlockWallet(driver, password)
    driver.get(r"https://zapper.fi/quests")
    assert "Zapper" in driver.title
    findHub(driver, "//button[text()='Connect Wallet']")
    findHub(driver, "//button/span[text()='MetaMask']")
    handles = driver.window_handles
    if len(handles) > 1:
        driver.switch_to.window(handles[1])
        time.sleep(5)
        findHub(driver, "//button[text()='Next']")
        findHub(driver,"//button[text()='Connect']")
        driver.switch_to.window(handles[0])
    findHub(driver,"//button[not(@disabled)]/span[text()='Claim']")
    handles = driver.window_handles
    
    if len(handles) > 1:
        driver.switch_to.window(handles[1])
        time.sleep(5)
        findHub(driver, "//button[text()='Sign']")
        driver.switch_to.window(handles[0])
    print("关闭浏览器")
    driver.close()

if __name__ == '__main__':
    while True:
        for x in range(1,10):
            claim('account'+str(x))
            print("完成任务")
        time.sleep(24*3600)

运行程序前,先要下载chrome的驱动(可以选择和你现在运行的chrome差不多的版本): https://chromedriver.storage.googleapis.com/index.html

下载后放到一个目录下,并在这个目录下创建多个文件夹。比如我在D盘创建了一个bin文件夹,里面包含chrome的驱动和多个代表每个账户的文件夹

image.png

首次启动,需要给每个浏览器添加小狐狸钱包插件,创建或导入钱包。

这是我设置Account10的过程:

setup.gif

设置好后就可以运行程序了

效果:
zapper.gif

代码里面设置是24小时运行一次,你可以随便更改

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  3 years ago 

村长厉害,!shop 拍拍

  ·  3 years ago 

like!!shop 好厉害 只有科学家能办到