From 07bb445e301e456a3e99814d3e6a01d1d38bda69 Mon Sep 17 00:00:00 2001 From: liuweiqing Date: Wed, 3 Apr 2024 21:03:32 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=AE=9A=E6=97=B6=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cron_read.yaml | 25 +++++++++++ .github/workflows/read.yaml | 26 ++++++++++++ puppeteer_c.js | 73 -------------------------------- 3 files changed, 51 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/cron_read.yaml create mode 100644 .github/workflows/read.yaml delete mode 100644 puppeteer_c.js diff --git a/.github/workflows/cron_read.yaml b/.github/workflows/cron_read.yaml new file mode 100644 index 00000000..5f401d2e --- /dev/null +++ b/.github/workflows/cron_read.yaml @@ -0,0 +1,25 @@ +name: Scheduled Node.js CI + +on: + schedule: + # 每天 UTC 时间 00:00 运行 + - cron: "0 0 * * *" + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] # 选择你需要的 Node.js 版本 + + steps: + - uses: actions/checkout@v3 # 检出你的仓库 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: pnpm i # 安装 package.json 中的依赖项 + - name: Run a script + run: node pteer.js # 替换为你想运行的脚本的实际名称 diff --git a/.github/workflows/read.yaml b/.github/workflows/read.yaml new file mode 100644 index 00000000..22269ff6 --- /dev/null +++ b/.github/workflows/read.yaml @@ -0,0 +1,26 @@ +name: Node.js CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] # 选择你需要的 Node.js 版本 + + steps: + - uses: actions/checkout@v3 # 检出你的仓库 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: pnpm i # 安装 package.json 中的依赖项 + - name: Run a script + run: node pteer.js # 替换为你想运行的脚本的实际名称 diff --git a/puppeteer_c.js b/puppeteer_c.js deleted file mode 100644 index cdf2850b..00000000 --- a/puppeteer_c.js +++ /dev/null @@ -1,73 +0,0 @@ -const fs = require("fs"); - -const path = require("path"); -const puppeteer = require("puppeteer"); -require("dotenv").config(); - -(async () => { - //随机等待时间 - function delayClick(time) { - return new Promise(function (resolve) { - setTimeout(resolve, time); - }); - } - const browser = await puppeteer.launch({ headless: false }); - const page = await browser.newPage(); - //登录操作 - await page.goto("https://linux.do"); - // 使用XPath查询找到包含"登录"或"login"文本的按钮 - await page.evaluate(() => { - const loginButton = Array.from(document.querySelectorAll("button")).find( - (button) => - button.textContent.includes("登录") || - button.textContent.includes("login") - ); - - if (loginButton) { - loginButton.click(); - } else { - console.log("Login button not found."); - } - }); - - // 等待用户名输入框加载 - await page.waitForSelector("#login-account-name"); - // 模拟人类在找到输入框后的短暂停顿 - await delayClick(500); // 延迟500毫秒 - // 清空输入框并输入用户名 - await page.click("#login-account-name", { clickCount: 3 }); - await page.type("#login-account-name", process.env.USERNAMELINUXDO, { - delay: 100, - }); // 输入时在每个按键之间添加额外的延迟 - - // 等待密码输入框加载 - await page.waitForSelector("#login-account-password"); - // 模拟人类在输入用户名后的短暂停顿 - await delayClick(500); - // 清空输入框并输入密码 - await page.click("#login-account-password", { clickCount: 3 }); - await page.type("#login-account-password", process.env.PASSWORD, { - delay: 100, - }); - - // 模拟人类在输入完成后思考的短暂停顿 - await delayClick(1000); - - // 假设登录按钮的ID是'login-button',点击登录按钮 - await page.waitForSelector("#login-button"); - await delayClick(500); // 模拟在点击登录按钮前的短暂停顿 - await page.click("#login-button"); - await delayClick(500); - - //真正执行阅读脚本 - // 读取外部脚本文件的内容 - const externalScriptPath = path.join(__dirname, "external.js"); - const externalScript = fs.readFileSync(externalScriptPath, "utf8"); - - // 在每个新的文档加载时执行外部脚本 - await page.evaluateOnNewDocument((...args) => { - const [scriptToEval] = args; - eval(scriptToEval); - }, externalScript); - await page.goto("https://linux.do/t/topic/13716/100"); -})();