37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { chromium } from 'playwright';
|
|
|
|
const userDataDir = '/Users/chick/.Hermes/workspace/research/xianyu-hunter/browser-data';
|
|
const out = '/tmp/xianyu-login-qr.png';
|
|
const ctx = await chromium.launchPersistentContext(userDataDir, {
|
|
headless: false,
|
|
viewport: { width: 1100, height: 900 },
|
|
locale: 'zh-CN',
|
|
args: ['--disable-blink-features=AutomationControlled', '--no-first-run'],
|
|
});
|
|
const page = ctx.pages()[0] || await ctx.newPage();
|
|
const loginUrl = 'https://login.taobao.com/member/login.jhtml?redirectURL=' + encodeURIComponent('https://www.goofish.com/');
|
|
await page.goto(loginUrl, { waitUntil: 'domcontentloaded', timeout: 45000 }).catch(async () => {
|
|
await page.goto('https://www.goofish.com/', { waitUntil: 'domcontentloaded', timeout: 45000 });
|
|
});
|
|
await page.waitForTimeout(5000);
|
|
for (const selector of [
|
|
'text=扫码登录',
|
|
'text=二维码登录',
|
|
'text=使用二维码登录',
|
|
'.icon-qrcode',
|
|
'[class*=qrcode]',
|
|
]) {
|
|
try {
|
|
const loc = page.locator(selector).first();
|
|
if (await loc.isVisible({ timeout: 1200 }).catch(() => false)) {
|
|
await loc.click({ timeout: 2000 }).catch(() => {});
|
|
await page.waitForTimeout(2500);
|
|
break;
|
|
}
|
|
} catch {}
|
|
}
|
|
await page.screenshot({ path: out, fullPage: false });
|
|
console.log(JSON.stringify({ ok: true, out, url: page.url(), title: await page.title().catch(()=>''), pid: process.pid }));
|
|
await page.waitForTimeout(5 * 60 * 1000);
|
|
await ctx.close().catch(() => {});
|