|
|
|
|
import re
|
|
|
|
|
from playwright.sync_api import Playwright, sync_playwright, expect
|
|
|
|
|
import time, datetime
|
|
|
|
|
from get_jd_timestamp import jd_timer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_firday():
|
|
|
|
|
today = datetime.datetime.strptime(datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d') + ' 20:00:00', '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
friday = today + datetime.timedelta( days=(4-today.weekday())%7)
|
|
|
|
|
print(friday)
|
|
|
|
|
return datetime.datetime.strftime(friday, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 需要每次定义
|
|
|
|
|
target: str = get_firday()
|
|
|
|
|
|
|
|
|
|
# 19920002680
|
|
|
|
|
user = {'mobile': '19920002680', 'password': 'Sxzgx1209'}
|
|
|
|
|
# 18611659484
|
|
|
|
|
# user = {'mobile': '18611659484', 'password': 'Rog129Sunx1532'}
|
|
|
|
|
|
|
|
|
|
target_timestamp = int(time.mktime(time.strptime(target, '%Y-%m-%d %H:%M:%S'))*1000)
|
|
|
|
|
AC_URL = f"https://h5static.m.jd.com/mall/active/xXzWGzxuJ6HRksjXms2x3cQsh25/index.html?utm_term=Wxfriends&utm_user=plusmember&utm_source=iosapp&utm_campaign=t_335139774&utm_medium=appshare&_ts={str(target_timestamp)}&ad_od=share&gxd=RnAowmYKPGXfnp4Sq4B_W578vOMp4E7JgUugKDcomXTOIlSPI-BCnvuytD0G7kc&gx=RnAomDgLPTTeyp5Z_sA9"
|
|
|
|
|
|
|
|
|
|
def run(playwright: Playwright) -> None:
|
|
|
|
|
|
|
|
|
|
browser = playwright.chromium.launch(headless=False)
|
|
|
|
|
context = browser.new_context()
|
|
|
|
|
page = context.new_page()
|
|
|
|
|
page.goto("https://www.jd.com/")
|
|
|
|
|
page.get_by_role("link", name="你好,请登录").click()
|
|
|
|
|
page.get_by_placeholder("账号名/手机号/邮箱").click()
|
|
|
|
|
page.get_by_placeholder("账号名/手机号/邮箱").fill(user['mobile']) # 19920002680 18611659484
|
|
|
|
|
page.get_by_placeholder("密码").fill(user['password'])
|
|
|
|
|
page.get_by_role("link", name="登 录").click()
|
|
|
|
|
|
|
|
|
|
time.sleep(30)
|
|
|
|
|
|
|
|
|
|
if page.get_by_text("切换账号"):
|
|
|
|
|
# 打开活动页面
|
|
|
|
|
print('登录成功!')
|
|
|
|
|
print(AC_URL)
|
|
|
|
|
page2 = context.new_page()
|
|
|
|
|
page2.goto(AC_URL)
|
|
|
|
|
# 倒计时
|
|
|
|
|
jd_timer(target)
|
|
|
|
|
# 点击领取
|
|
|
|
|
page2.click(".coupon_wrapper")
|
|
|
|
|
target_name = target.replace(':', '-').replace(' ', '_')
|
|
|
|
|
page2.screenshot(path=f"{target_name}.png")
|
|
|
|
|
print('点击立即领取!')
|
|
|
|
|
time.sleep(100)
|
|
|
|
|
|
|
|
|
|
# ---------------------
|
|
|
|
|
context.close()
|
|
|
|
|
browser.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with sync_playwright() as playwright:
|
|
|
|
|
run(playwright)
|