-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
48 lines (31 loc) · 843 Bytes
/
app.js
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
const puppeteer = require('puppeteer')
const { saveCookie, getCookie } = require('./login')
const websites = {
juejin: 'juejin'
}
const app = async() => {
const browser = await puppeteer.launch({ headless: false })
const page = await browser.newPage()
await page.setViewport({
width: 1920,
height: 1080
})
await Promise.all([
page.goto('https://juejin.cn/'),
page.waitForNavigation([
'load',
'domcontentloaded',
'networkidle0'
])
])
// 获取指定网站cookie,如果本地文件没有存储,则进行存储
let cookie = await getCookie(websites.juejin)
if(!cookie) {
console.log('需要登入...')
await saveCookie(page, websites.juejin)
cookie = await getCookie(websites.juejin)
}
await page.setCookie(...cookie)
await page.reload()
}
app()