mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
🔨 refactor(browser/scraper): Код оптимизирован и обработка ошибок улучшена
All checks were successful
Deploy / deploy (push) Successful in 46s
All checks were successful
Deploy / deploy (push) Successful in 46s
This commit is contained in:
@@ -16,7 +16,15 @@ export async function randomScroll(page: Page): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getBrowser(): Promise<Browser> {
|
export async function getBrowser(): Promise<Browser> {
|
||||||
return chromium.launch({ headless: !!(process.env?.debug ?? true) })
|
return chromium.launch({
|
||||||
|
headless: !!(process.env?.debug ?? true),
|
||||||
|
args: [
|
||||||
|
'--no-sandbox',
|
||||||
|
'--disable-setuid-sandbox',
|
||||||
|
'--disable-dev-shm-usage',
|
||||||
|
'--disable-gpu',
|
||||||
|
],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadSession(page: Page, telegramId: bigint | number): Promise<boolean> {
|
export async function loadSession(page: Page, telegramId: bigint | number): Promise<boolean> {
|
||||||
|
|||||||
@@ -61,47 +61,51 @@ export async function login(email: string, chatId: number): Promise<void> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = await browser.newContext()
|
try {
|
||||||
const page = await context.newPage()
|
const context = await browser.newContext()
|
||||||
|
const page = await context.newPage()
|
||||||
|
|
||||||
await page.goto('https://hh.ru/account/login', { waitUntil: 'domcontentloaded' })
|
await page.goto('https://hh.ru/account/login', { waitUntil: 'domcontentloaded' })
|
||||||
// await bot.sendMessage(chatId, `page: ${page.url()}`)
|
// await bot.sendMessage(chatId, `page: ${page.url()}`)
|
||||||
|
|
||||||
await page.click('[data-qa="submit-button"]')
|
await page.click('[data-qa="submit-button"]')
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
// await bot.sendMessage(chatId, `Клик по "Войти"`)
|
// await bot.sendMessage(chatId, `Клик по "Войти"`)
|
||||||
|
|
||||||
await page.click('label:has([data-qa="credential-type-EMAIL"])')
|
await page.click('label:has([data-qa="credential-type-EMAIL"])')
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
// await bot.sendMessage(chatId, `Клик по "Email"`)
|
// await bot.sendMessage(chatId, `Клик по "Email"`)
|
||||||
|
|
||||||
await page.fill('[data-qa="applicant-login-input-email"]', email)
|
await page.fill('[data-qa="applicant-login-input-email"]', email)
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
// await bot.sendMessage(chatId, `Ввод "Email"`)
|
// await bot.sendMessage(chatId, `Ввод "Email"`)
|
||||||
|
|
||||||
await page.click('[data-qa="submit-button"]')
|
await page.click('[data-qa="submit-button"]')
|
||||||
// await bot.sendMessage(chatId, `Клик по "Дальше"`)
|
// await bot.sendMessage(chatId, `Клик по "Дальше"`)
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
|
|
||||||
await bot.sendMessage(chatId, '🔑 Введи код из email')
|
await bot.sendMessage(chatId, '🔑 Введи код из email')
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
|
|
||||||
await page.click('[data-qa="applicant-login-input-otp"]')
|
await page.click('[data-qa="applicant-login-input-otp"]')
|
||||||
const otp = await waitForOtp(chatId)
|
const otp = await waitForOtp(chatId)
|
||||||
await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||||
// await bot.sendMessage(chatId, `Введён ОТП: ${otp}`)
|
// await bot.sendMessage(chatId, `Введён ОТП: ${otp}`)
|
||||||
|
|
||||||
await page.waitForTimeout(randomDelay())
|
await page.waitForTimeout(randomDelay())
|
||||||
await page.waitForSelector('[data-qa="profileAndResumes-button"]', { timeout: 15000 })
|
await page.waitForSelector('[data-qa="profileAndResumes-button"]', { timeout: 15000 })
|
||||||
|
|
||||||
const cookies = await context.cookies()
|
const cookies = await context.cookies()
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { telegramId: chatId },
|
where: { telegramId: chatId },
|
||||||
data: { session: JSON.stringify(cookies, null, 2) },
|
data: { session: JSON.stringify(cookies, null, 2) },
|
||||||
})
|
})
|
||||||
|
|
||||||
await bot.sendMessage(chatId, cookies.length > 0 ? '✅ Авторизация выполнена' : '❌ Произошла ошибка')
|
await bot.sendMessage(chatId, cookies.length > 0 ? '✅ Авторизация выполнена' : '❌ Произошла ошибка')
|
||||||
await browser.close()
|
}
|
||||||
|
finally {
|
||||||
|
await browser.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkIsAuth(telegramId: bigint | number) {
|
export async function checkIsAuth(telegramId: bigint | number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user