用playwright基本不管是啥网站都可以实现自动签到等各种操作,这里是自用代码,给大家做个参考。
没有直接用cookie而是每次输入账号密码登录是因为这个网站好像过一段时间cookie就会失效。
代码如下:
import time
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
chromium = p.chromium
browser = chromium.launch(headless=True)
page = browser.new_page()
page.goto('https://www.element3ds.com/member.php?mod=logging&action=login&referer=')
page.fill('xpath=/html/body/div[4]/div[2]/div[3]/div/div[1]/div/div[1]/form/div/div[1]/table/tbody/tr/td/input', '987654321') # 输入账号
time.sleep(1)
page.fill('xpath=/html/body/div[4]/div[2]/div[3]/div/div[1]/div/div[1]/form/div/div[2]/table/tbody/tr/td/input', '12345678') # 输入密码
time.sleep(1)
page.query_selector('xpath=/html/body/div[4]/div[2]/div[3]/div/div[1]/div/div[1]/form/div/div[3]/table/tbody/tr/td/button/strong').click()
time.sleep(6)
page.goto('https://www.element3ds.com/plugin.php?id=yinxingfei_zzza:yinxingfei_zzza_hall')
a = page.query_selector('#body > div:nth-child(11) > div.zzza_hall_main.cl > div.zzza_hall_top > div.zzza_hall_top_right > div > div.zzza_hall_bottom_right_yjan_left > a').text_content()
if a == '已经摇过' :
day = page.query_selector(
'#body > div:nth-child(11) > div.zzza_hall_main.cl > div.zzza_hall_top > div:nth-child(2) > div.zzza_hall_top_left_infor > ul > li:nth-child(3) > span:nth-child(2)').text_content()
print('微元素连续摇奖 %s 天' % (day))
else:
try:
page.query_selector('#body > div:nth-child(11) > div.zzza_hall_main.cl > div.zzza_hall_top > div.zzza_hall_top_right > div > div.zzza_hall_bottom_right_yjan_left > a').click()
time.sleep(1)
page.query_selector('#body > div.tips-boxov > div.tips-box > div.tps-bottom > a:nth-child(1)').click()
time.sleep(1)
page.query_selector('#zzza_go').click()
time.sleep(6)
page.goto('https://www.element3ds.com/plugin.php?id=yinxingfei_zzza:yinxingfei_zzza_hall')
a = page.query_selector(
'#body > div:nth-child(11) > div.zzza_hall_main.cl > div.zzza_hall_top > div.zzza_hall_top_right > div > div.zzza_hall_bottom_right_yjan_left > a').text_content()
if a == '已经摇过':
day = page.query_selector(
'#body > div:nth-child(11) > div.zzza_hall_main.cl > div.zzza_hall_top > div:nth-child(2) > div.zzza_hall_top_left_infor > ul > li:nth-child(3) > span:nth-child(2)').text_content()
print('微元素连续摇奖 %s 天' % (day))
except:
print('微元素签到失败')
page.close()
Comments NOTHING