-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
86 lines (70 loc) · 3.01 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import puppeteer from 'puppeteer'
import { Readline } from "./src";
class Start {
// @ts-ignore
page: puppeteer.Page;
isInitFinish: boolean = false;
isStartBeforeInit: boolean = false;
constructor() {
this.init()
}
private init = async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--process-per-site'],
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
devtools: true,
});
this.page = await browser.newPage();
await this.page.setViewport({ width: 1000, height: 500});
this.isInitFinish = true;
if (this.isStartBeforeInit) {
this.start()
}
}
public start = async () => {
if (!this.isInitFinish) {
console.info('初始化未完成,初始化完成后启动浏览器');
this.isStartBeforeInit = true;
return;
}
// await this.page.goto('http://sso.souche-inc.com/login.htm?s=aHR0cHM6Ly9kYXRhc3RhbmRhcmQuc291Y2hlLWluYy5jb20vIy9zdGFuZGFyZA==');
await this.page.goto('http://sso.dasouche-inc.net/phoneCheck.htm?s=aHR0cDovL2YyZS5zb3VjaGUuY29tL3Byb2plY3RzL2RhdGEtZmUvZGF0YS1zdGFuZGFyZC1jZW50ZXIvaW5kZXguaHRtbCMvbW9kZWxDc3Q=');
const canPasswordLogin = await this.getCanPasswordLogin();
console.log('------> canPasswordLogin', canPasswordLogin);
// 不用密码登录了
await this.verificationCodeLogin();
// 等待加载左侧导航
await this.page.waitForSelector(".ant-tree-node-content-wrapper")
await this.page.click(".ant-tree-node-content-wrapper")
// await this.page.click(".ant-tree-node-content-wrapper")
}
private getCanPasswordLogin = async(): Promise<boolean> => {
// const firstATag = await this.page.$("a[href='/phoneCheck.htm?s=aHR0cDovL2YyZS5zb3VjaGUuY29tL3Byb2plY3RzL2RhdGEtZmUvZGF0YS1zdGFuZGFyZC1jZW50ZXIvaW5kZXguaHRtbCMvc3RhbmRhcmQ=']");
const aTagsInnerHTML = await this.page.$$eval("a", aTags => aTags.map((aTag => aTag.innerHTML)));
console.log('------> aTagsInnerHTML', aTagsInnerHTML);
// 如果有忘记密码,说明在密码登录页面
const isContainerPassword = aTagsInnerHTML.includes("忘记密码?")
if (isContainerPassword) {
return true;
}
return false;
}
private passwordLogin = async () => {
}
private verificationCodeLogin = async () => {
// 输入用户名
await this.page.type("#fg-username", "15067422155");
// 勾选发送验证码到钉钉
await this.page.click("#beleive-ckb");
// 点击获取验证码
await this.page.click("#msg_code");
const answer = await Readline.question("请输入验证码");
// 输入验证码
await this.page.type("#fg-code-verify", answer);
// 点击确认按钮
await this.page.click("#fgpwd-submit-btn");
}
}
const start = new Start();
start.start();