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