mirror of
https://github.com/zhao-zg/jd-login.git
synced 2026-01-12 05:10:42 +08:00
Update login.py
This commit is contained in:
parent
05534c4080
commit
9ee025085f
98
login.py
98
login.py
@ -50,6 +50,17 @@ supported_colors = {
|
||||
"红色": ([0, 50, 50], [10, 255, 255]),
|
||||
}
|
||||
|
||||
|
||||
async def deleteSessionDelay(workList, uid):
|
||||
s = workList.get(uid, "")
|
||||
if s:
|
||||
await asyncio.sleep(15)
|
||||
del workList[uid]
|
||||
async def deleteSession(workList, uid):
|
||||
s = workList.get(uid, "")
|
||||
if s:
|
||||
del workList[uid]
|
||||
|
||||
async def loginPhone(chromium_path, workList, uid, headless):
|
||||
# 判断账号密码错误
|
||||
async def isWrongAccountOrPassword(page, verify=False):
|
||||
@ -82,9 +93,7 @@ async def loginPhone(chromium_path, workList, uid, headless):
|
||||
# 判断验证码超时
|
||||
async def needResendSMSCode(page):
|
||||
try:
|
||||
if await page.querySelector('.getMsg-btn.text-btn.timer.active'):
|
||||
return True
|
||||
return False
|
||||
return await page.querySelector('.getMsg-btn.text-btn.timer.active');
|
||||
except Exception as e:
|
||||
logger.info("needResendSMSCode " + str(e))
|
||||
return False
|
||||
@ -202,28 +211,15 @@ async def loginPhone(chromium_path, workList, uid, headless):
|
||||
|
||||
await asyncio.sleep(1)
|
||||
except Exception as e:
|
||||
logger.info("异常退出")
|
||||
logger.error(e)
|
||||
workList[uid].msg = "服务器异常退出"
|
||||
workList[uid].status = "error"
|
||||
workList[uid].msg = "异常退出"
|
||||
break
|
||||
print("异常退出")
|
||||
print(e)
|
||||
await browser.close()
|
||||
await deleteSessionDelay(workList, uid)
|
||||
raise e
|
||||
|
||||
logger.info("任务完成退出")
|
||||
|
||||
logger.info("任务完成退出")
|
||||
logger.info("开始删除缓存文件......")
|
||||
if os.path.exists("image.png"):
|
||||
os.remove("image.png")
|
||||
if os.path.exists("template.png"):
|
||||
os.remove("template.png")
|
||||
if os.path.exists("shape_image.png"):
|
||||
os.remove("shape_image.png")
|
||||
if os.path.exists("rgba_word_img.png"):
|
||||
os.remove("rgba_word_img.png")
|
||||
if os.path.exists("rgb_word_img.png"):
|
||||
os.remove("rgb_word_img.png")
|
||||
logger.info("缓存文件已删除!")
|
||||
logger.info("开始关闭浏览器....")
|
||||
print("任务完成退出")
|
||||
await browser.close()
|
||||
logger.info("浏览器已关闭!")
|
||||
return
|
||||
@ -250,7 +246,13 @@ async def loginPassword(chromium_path, workList, uid, headless):
|
||||
# 判断验证码错误
|
||||
async def isStillInSMSCodeSentPage(page):
|
||||
try:
|
||||
if not await page.querySelector('.getMsg-btn.timer.active') and await page.querySelector('.acc-input.msgCode'):
|
||||
if await page.xpath('//*[@id="header"]/span[2]'):
|
||||
element = await page.xpath('//*[@id="header"]/span[2]')
|
||||
if element:
|
||||
text = await page.evaluate(
|
||||
"(element) => element.textContent", element[0]
|
||||
)
|
||||
if text == "手机短信验证":
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
@ -260,7 +262,13 @@ async def loginPassword(chromium_path, workList, uid, headless):
|
||||
# 判断验证码超时
|
||||
async def needResendSMSCode(page):
|
||||
try:
|
||||
if await page.querySelector('.getMsg-btn.timer.active'):
|
||||
if await page.xpath('//*[@id="app"]/div/div[2]/div[2]/button'):
|
||||
element = await page.xpath('//*[@id="app"]/div/div[2]/div[2]/button')
|
||||
if element:
|
||||
text = await page.evaluate(
|
||||
"(element) => element.textContent", element[0]
|
||||
)
|
||||
if text == "获取验证码":
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
@ -494,9 +502,9 @@ async def loginPassword(chromium_path, workList, uid, headless):
|
||||
content = await page.content()
|
||||
with open(f"error_{usernum}-html-{dateTime}.html", 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
workList[uid].status = "error"
|
||||
workList[uid].msg = "异常退出"
|
||||
break
|
||||
await browser.close()
|
||||
await deleteSessionDelay(workList, uid)
|
||||
raise e
|
||||
|
||||
logger.info("任务完成退出")
|
||||
logger.info("开始删除缓存文件......")
|
||||
@ -561,22 +569,21 @@ async def typephoneuser(page, usernum):
|
||||
await page.waitFor(random.randint(200, 500))
|
||||
await page.click(".getMsg-btn.text-btn.timer")
|
||||
await page.waitFor(random.randint(500, 1000))
|
||||
|
||||
async def typeuser(page, usernum, passwd):
|
||||
logger.info("开始输入账号密码")
|
||||
print("开始输入账号密码")
|
||||
await page.waitForSelector(".J_ping.planBLogin")
|
||||
await page.click(".J_ping.planBLogin")
|
||||
await page.type(
|
||||
"#username", usernum, {"delay": random.randint(60, 121)}
|
||||
"#username", usernum, {"delay": random.randint(10, 20)}
|
||||
)
|
||||
await page.type(
|
||||
"#pwd", passwd, {"delay": random.randint(100, 151)}
|
||||
"#pwd", passwd, {"delay": random.randint(10, 20)}
|
||||
)
|
||||
await page.waitFor(random.randint(100, 2000))
|
||||
await page.waitFor(random.randint(200, 500))
|
||||
await page.click(".policy_tip-checkbox")
|
||||
await page.waitFor(random.randint(100, 2000))
|
||||
await page.waitFor(random.randint(200, 500))
|
||||
await page.click(".btn.J_ping.btn-active")
|
||||
await page.waitFor(random.randint(100, 2000))
|
||||
await page.waitFor(random.randint(500, 1000))
|
||||
|
||||
|
||||
async def sendSMSDirectly(page):
|
||||
@ -596,7 +603,7 @@ async def sendSMSDirectly(page):
|
||||
|
||||
try:
|
||||
while True:
|
||||
if await page.xpath('//*[@id="small_img"]'):
|
||||
if await page.xpath('//*[@id="captcha_modal"]/div/div[3]/div'):
|
||||
await verification(page)
|
||||
|
||||
elif await page.xpath('//*[@id="captcha_modal"]/div/div[3]/button'):
|
||||
@ -638,7 +645,7 @@ async def sendSMS(page):
|
||||
|
||||
try:
|
||||
while True:
|
||||
if await page.xpath('//*[@id="small_img"]'):
|
||||
if await page.xpath('//*[@id="captcha_modal"]/div/div[3]/div'):
|
||||
await verification(page)
|
||||
|
||||
elif await page.xpath('//*[@id="captcha_modal"]/div/div[3]/button'):
|
||||
@ -904,9 +911,7 @@ async def verification_shape(page):
|
||||
|
||||
# 文字点选的重试次数,超过将重启浏览器
|
||||
retry_count = 10
|
||||
i = 5
|
||||
while i > 0:
|
||||
i -= 1
|
||||
for i in range(5):
|
||||
await page.waitForSelector("div.captcha_footer img")
|
||||
image_src = await page.Jeval(
|
||||
"#cpc_img", 'el => el.getAttribute("src")'
|
||||
@ -1194,5 +1199,16 @@ async def main(workList, uid, oocr, oocrDet):
|
||||
await asyncio.sleep(random.uniform(2, 4))
|
||||
logger.info(f"进行第{try_time}次重试")
|
||||
try_time += 1
|
||||
logger.info("登录完成")
|
||||
if os.path.exists("image.png"):
|
||||
os.remove("image.png")
|
||||
if os.path.exists("template.png"):
|
||||
os.remove("template.png")
|
||||
if os.path.exists("shape_image.png"):
|
||||
os.remove("shape_image.png")
|
||||
if os.path.exists("rgba_word_img.png"):
|
||||
os.remove("rgba_word_img.png")
|
||||
if os.path.exists("rgb_word_img.png"):
|
||||
os.remove("rgb_word_img.png")
|
||||
await deleteSessionDelay(workList, uid)
|
||||
print("登录完成")
|
||||
await asyncio.sleep(10)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user