-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfa4399
commit 036c096
Showing
4 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
EMAIL= | ||
PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
import { config } from "https://deno.land/x/dotenv/mod.ts"; | ||
import puppeteer from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const browser = await puppeteer.launch({ | ||
headless: true, // 设置为false以便观察浏览器动作,调试时很有用 | ||
headless: false, // 设置为false以便观察浏览器动作,调试时很有用 | ||
args: ['--disable-web-security'] | ||
}); | ||
|
||
const page = await browser.newPage(); | ||
const env = config(); | ||
const email = env.EMAIL; | ||
const password = env.PASSWORD; | ||
|
||
|
||
const page = await browser.newPage(); | ||
await page.setViewport({ width: 1280, height: 800 }); | ||
const client = await page.target().createCDPSession(); | ||
const downloadPath = "./public"; | ||
|
||
await client.send('Page.setDownloadBehavior', { | ||
behavior: 'allow', | ||
downloadPath: downloadPath | ||
}); | ||
|
||
await page.goto("https://typst.app/project/rIWFtNvpmsgHgh18iqpk2a"); | ||
await page.goto("https://typst.app/project/r3N_OX7ukxFZcoaITyqR2p"); | ||
|
||
try { | ||
await page.waitForTimeout(5000) | ||
await page.waitForSelector('#email'); | ||
await page.evaluate((email, password) => { | ||
document.querySelector('#email').value = email; | ||
document.querySelector('#password').value = password; | ||
document.querySelector('#target > form > div.submit-row > input[type=submit]').click(); | ||
}, email, password); | ||
console.log('登录成功') | ||
await page.waitForTimeout(10000) | ||
// 等待带有aria-label="Quick export PDF"的按钮出现,最多等待10秒钟 | ||
await page.waitForSelector('button[aria-label="Quick export PDF"]', { timeout: 20000 }); | ||
await page.waitForSelector('button[aria-label="Quick export PDF"]', { timeout: 10000 }); | ||
console.log('页面加载完毕') | ||
// 找到并点击带有aria-label="Quick export PDF"的按钮 | ||
const quickExportPDFButton = await page.$('button[aria-label="Quick export PDF"]'); | ||
|
@@ -33,4 +46,4 @@ try { | |
console.error('操作超时或发生错误:', error); | ||
} | ||
|
||
await browser.close(); | ||
await browser.close(); |