File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 3535 - name : Install Puppeteer
3636 run : |
3737 npm install puppeteer
38-
3938 - name : Take screenshot
4039 run : |
4140 node -e "const puppeteer = require('puppeteer');
@@ -55,18 +54,31 @@ jobs:
5554 });
5655
5756 // 等待页面内容加载
58- await page.waitForSelector('. main-content ', {timeout: 30000}).catch(() => console.log('正在等待内容加载...'));
57+ await page.waitForSelector('main', {timeout: 30000}).catch(() => console.log('正在等待内容加载...'));
5958
6059 // 额外等待时间让JavaScript完全执行
6160 await page.waitForTimeout(5000);
6261
6362 // 确保 Images 目录存在
6463 await require('fs').promises.mkdir('./Images', { recursive: true }).catch(() => {});
6564
66- // 截图
67- await page.screenshot({path: './Images/DDL.png', fullPage: true});
65+ // 根据XPath找到元素
66+ const mainElement = await page.$x('/html/body/div[1]/div[2]/main');
67+ if (mainElement.length > 0) {
68+ // 只截取main元素部分
69+ await mainElement[0].screenshot({
70+ path: './Images/DDL.png'
71+ });
72+ console.log('成功截取main元素');
73+ } else {
74+ // 如果找不到元素,退回到全页截图
75+ console.log('无法找到指定元素,使用全页截图');
76+ await page.screenshot({path: './Images/DDL.png', fullPage: true});
77+ }
78+
6879 await browser.close();
69- })();"
80+ })();" # 使用 Node.js 脚本执行 Puppeteer 代码
81+
7082 - name : Push changes
7183 run : |
7284 git config --global user.name 'github-actions'
You can’t perform that action at this time.
0 commit comments