修复 google 登录中错误

This commit is contained in:
yema 2023-06-05 20:13:42 +08:00
parent 49d36516c1
commit 828e987119
7 changed files with 205 additions and 157 deletions

View File

@ -38,7 +38,7 @@ export async function login(options, tryCount = 1): Promise<Page> {
// log('准备进入 google 登录页')
const [response] = await Promise.all([
page.waitForNavigation(() => location.href.startsWith('https://auth0.openai.com/u/login/identifier')),
page.waitForNavigation({ timeout: 10000 }),
page.click('button')
])
// log('已进入 google 登录页')

View File

@ -1,52 +0,0 @@
import { clog, loginGoogle } from './login'
import { readFileSync, writeFileSync } from 'fs'
import path from 'path'
import { EOL } from 'os'
export async function getLink(options) {
const log = clog(options)
log('开始', { ident: 'poe-link' })
const page = await loginGoogle(options)
await Promise.all([
page.waitForNavigation(),
page.goto('https://poe.com/settings')
])
log('已进入设置页面, 检查中')
// page.waitForTimeout(1000)
await page.waitForSelector('[class*=SettingsSubscriptionSection_subscribeButton]')
log('1, 开始点击显示订阅套餐按钮')
await page.click('[class*=SettingsSubscriptionSection_subscribeButton]')
log('2, 开始点击显示更多套餐')
await page.waitForSelector('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]')
await page.click('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]')
log('3, 开始点击最后一个套餐')
await page.waitForSelector('[class*=WebSubscriptionPaywall_plans]')
await page.click('[class*=WebSubscriptionPaywall_plans] > button:last-child')
// 点击订阅
log('4, 开始点击订阅')
page.click('[class*=WebSubscriptionPaywall_button]')
const [response] = await Promise.all([
page.waitForNavigation({ waitUntil: 'domcontentloaded' }),
])
if (response.ok()) {
const url = response._request._frame._url
log('获取链接成功', { result: url, type: 'success' })
return url
// if (options.index === 0) {
// writeFileSync(resolve('./hao.txt'), '', 'utf8')
// }
// const fileContent = readFileSync(resolve('./hao.txt'), 'utf8')
// writeFileSync(resolve('./hao.txt'), fileContent + `${EOL}${options.index + 1} ${options.user}${EOL}${url}`, 'utf8')
}
}
function resolve(url) {
return path.resolve(__dirname, '../src/poe/', url)
}

View File

@ -0,0 +1,74 @@
import { clog, loginGoogle } from './login'
import type { Browser, Page } from 'puppeteer'
import { readFileSync, writeFileSync } from 'fs'
import path from 'path'
import { EOL } from 'os'
function existDialog(page: Page) {
return page.evaluate((selector, searchText) => {
const elements = Array.from(document.querySelectorAll(selector));
const target = elements.find(el => el.textContent.trim() === searchText);
target && target.click()
return !!target
}, 'button', 'Start free trial')
}
export async function getLink(options) {
const log = clog(options)
log('开始', { ident: 'poe-link' })
return loginGoogle(options).then(async (page: Page) => {
await page.waitForTimeout(1000)
const isExistDialog = await existDialog(page)
isExistDialog && log('检测到充值弹窗,无需前往设置页')
if (!isExistDialog) {
await Promise.all([
page.waitForNavigation(),
page.goto('https://poe.com/settings')
])
log('已进入设置页面, 检查中')
await page.waitForSelector('[class*=SettingsSubscriptionSection_subscribeButton]')
log('点击显示订阅套餐按钮')
await page.click('[class*=SettingsSubscriptionSection_subscribeButton]')
}
log('显示更多套餐')
await page.waitForSelector('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]')
await page.click('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]')
log('点击最后一个套餐')
await page.waitForSelector('[class*=WebSubscriptionPaywall_plans]')
await page.click('[class*=WebSubscriptionPaywall_plans] > button:last-child')
// 点击订阅
log('4, 开始点击订阅')
page.click('[class*=WebSubscriptionPaywall_button]')
const [response] = await Promise.all([
page.waitForNavigation({ waitUntil: 'domcontentloaded' }),
])
if (response.ok()) {
const url = response._request._frame._url
log('获取链接成功', { result: url, type: 'success' })
return url
// if (options.index === 0) {
// writeFileSync(resolve('./hao.txt'), '', 'utf8')
// }
// const fileContent = readFileSync(resolve('./hao.txt'), 'utf8')
// writeFileSync(resolve('./hao.txt'), fileContent + `${EOL}${options.index + 1} ${options.user}${EOL}${url}`, 'utf8')
}
}).catch(error => {
console.log('error ->', error.try, error.text, error)
if (error?.try) {
return getLink(options)
}
})
}
function resolve(url) {
return path.resolve(__dirname, '../src/poe/', url)
}

View File

@ -1,13 +1,13 @@
import type { Browser, Page } from 'puppeteer'
import puppeteer from 'puppeteer-extra'
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
import { randomNum } from '../tools'
import { randomNum, awaitWrap } from '../tools'
import { win } from '../index'
puppeteer.use(StealthPlugin())
let id
export let browser
export let browser: Browser
/**
* google
*/
@ -38,10 +38,13 @@ export async function loginGoogle(options, tryCount = 1) {
await page.waitForTimeout(randomNum(1000, 2600))
log('准备进入 google 登录页')
const [response] = await Promise.all([
page.waitForNavigation(() => location.href.startsWith('https://accounts.google.com')),
page.click('.ContinueWithGoogleButton_buttonContentWrapper__Mrp0W')
])
page.click('.ContinueWithGoogleButton_buttonContentWrapper__Mrp0W')
const [err, response] = await awaitWrap(page.waitForNavigation({ timeout: 10000 }))
if (err) {
reject({ text: '登录报错', try: true })
return p
}
log('已进入 google 登录页')
if (response.ok()) {
@ -53,6 +56,11 @@ export async function loginGoogle(options, tryCount = 1) {
await page.keyboard.press('Enter')
])
log('已输入账号,准备输入密码')
if (await isError(page)) {
reject({ text: '登录报错', try: true })
return p
}
await page.waitForSelector('input[type="password"]', { visible: true })
await page.type('input[type="password"]', env.GPASS)
log('已输入密码,开始登录')
@ -60,6 +68,10 @@ export async function loginGoogle(options, tryCount = 1) {
page.waitForFunction(() => location.href === 'https://poe.com/'),
await page.keyboard.press('Enter')
])
if (await isError(page)) {
reject({ text: '登录报错', try: true })
return p
}
log('登录成功,准备进入 poe')
@ -79,11 +91,17 @@ export async function loginGoogle(options, tryCount = 1) {
// return Promise.reject('google 登录失败')
}
async function isError(page: Page) {
const text = await page.evaluate(() => (document.querySelector('p')?.textContent || ''));
// const text = await page.evaluate('p', element => element.textContent);
return text && text.includes('error')
}
export function clog(options) {
return (info, data = {}) => {
if (win) {
win.webContents.send('progress', {...options, info, ...data})
win.webContents.send('progress', { ...options, info, ...data })
}
}
}

View File

@ -1,5 +0,0 @@
//生成从minNum到maxNum的随机数
export function randomNum (min, max) {
return parseInt(Math.random() * (max - min + 1) + min)
}

12
electron/main/tools.ts Normal file
View File

@ -0,0 +1,12 @@
//生成从minNum到maxNum的随机数
export function randomNum (min, max) {
return parseInt(Math.random() * (max - min + 1) + min)
}
// promise 错误处理
export function awaitWrap<T, U = any>(promise: Promise<T>): Promise<[U | null, T | null]> {
return promise
.then<[null, T]>((data: T) => [null, data])
.catch<[U, null]>(err => [err, null])
}

View File

@ -2,99 +2,100 @@
import { ipcRenderer } from 'electron'
import { NButton } from 'naive-ui'
import { useClipboard } from '@vueuse/core'
const input = ref('upperside79@mail.com----Hellowpo!')
const input = ref('126vdsjmgyanpgqrvb@ddmvp.icu----EOJ2NgPfS')
// const input = ref('traceetakashi6274@gmail.com----kedaraditi0214----kedaraditi4760@hotmail.com')
const result = ref('')
const list = ref<any[]>([
{
"user": "jannettamoses5977@gmail.com",
"pass": "kenyatearle7610",
"auxiliary": "kenyatearle8223@outlook.com",
"index": 0,
"id": "jannettamoses5977@gmail.com",
"info": "成功😘",
"ident": "poe-link",
"type": "success",
"result": "成功😘"
},
{
"user": "tylanindea7687@gmail.com",
"pass": "adalbertokanisha4845",
"auxiliary": "adalbertokanisha8803@yandex.com",
"index": 1,
"id": "tylanindea7687@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
},
{
"user": "bayanjae8652@gmail.com",
"pass": "lorenarosamond4075",
"auxiliary": "lorenarosamond8958@outlook.com",
"index": 2,
"id": "bayanjae8652@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "fail",
"result": "成功😘"
},
{
"user": "geneviashametra1019@gmail.com",
"pass": "sheypervis2156",
"auxiliary": "sheypervis0163@qq.com",
"index": 3,
"id": "geneviashametra1019@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
},
{
"user": "marikamelindasue5911@gmail.com",
"pass": "ambrbreeann4103",
"auxiliary": "ambrbreeann5643@icloud.com",
"index": 4,
"id": "marikamelindasue5911@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
},
{
"user": "caterinereba2981@gmail.com",
"pass": "arvisleo0563",
"auxiliary": "arvisleo1265@zoho.com",
"index": 5,
"id": "caterinereba2981@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
},
{
"user": "adairaderrell9992@gmail.com",
"pass": "adairaderrell8698",
"auxiliary": "adairaderrell1859@hotmail.com",
"index": 6,
"id": "adairaderrell9992@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
},
{
"user": "nishadarrow0444@gmail.com",
"pass": "cliftontiffani7462",
"auxiliary": "cliftontiffani2263@hotmail.com",
"index": 7,
"id": "nishadarrow0444@gmail.com",
"info": "成功😘",
"ident": "poe-validate",
"type": "success",
"result": "成功😘"
}
// {
// "user": "jannettamoses5977@gmail.com",
// "pass": "kenyatearle7610",
// "auxiliary": "kenyatearle8223@outlook.com",
// "index": 0,
// "id": "jannettamoses5977@gmail.com",
// "info": "😘",
// "ident": "poe-link",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "tylanindea7687@gmail.com",
// "pass": "adalbertokanisha4845",
// "auxiliary": "adalbertokanisha8803@yandex.com",
// "index": 1,
// "id": "tylanindea7687@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "bayanjae8652@gmail.com",
// "pass": "lorenarosamond4075",
// "auxiliary": "lorenarosamond8958@outlook.com",
// "index": 2,
// "id": "bayanjae8652@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "fail",
// "result": "😘"
// },
// {
// "user": "geneviashametra1019@gmail.com",
// "pass": "sheypervis2156",
// "auxiliary": "sheypervis0163@qq.com",
// "index": 3,
// "id": "geneviashametra1019@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "marikamelindasue5911@gmail.com",
// "pass": "ambrbreeann4103",
// "auxiliary": "ambrbreeann5643@icloud.com",
// "index": 4,
// "id": "marikamelindasue5911@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "caterinereba2981@gmail.com",
// "pass": "arvisleo0563",
// "auxiliary": "arvisleo1265@zoho.com",
// "index": 5,
// "id": "caterinereba2981@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "adairaderrell9992@gmail.com",
// "pass": "adairaderrell8698",
// "auxiliary": "adairaderrell1859@hotmail.com",
// "index": 6,
// "id": "adairaderrell9992@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// },
// {
// "user": "nishadarrow0444@gmail.com",
// "pass": "cliftontiffani7462",
// "auxiliary": "cliftontiffani2263@hotmail.com",
// "index": 7,
// "id": "nishadarrow0444@gmail.com",
// "info": "😘",
// "ident": "poe-validate",
// "type": "success",
// "result": "😘"
// }
])
ipcRenderer.on('progress', (event, args) => {
@ -142,8 +143,8 @@ const listFail = computed(() => {
})
const { copy } = useClipboard()
function copyText(item: any) {
copy(item.user + '----' + (item.result || ''))
function copyText(text: any) {
copy(text)
}
function copyAccount(item: any) {
copy(item.user + '----' + item.pass + '----' + item.auxiliary)