-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (40 loc) · 1.26 KB
/
index.js
File metadata and controls
44 lines (40 loc) · 1.26 KB
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
const core = require('@actions/core');
const puppeteer = require('puppeteer');
const Path = require('path');
const fs = require('fs');
// Puppeteer configuration
const configuration = {
headless: true, // true: headless mode, false: display browser
defaultViewport: {
width: 1600,
height: 1200
},
args: [
'--no-sandbox', // Avoid the impact of security restrictions (for CI environments)
'--disable-setuid-sandbox'
]
};
const url = 'https://developer.apple.com/app-store/review/guidelines';
const filePath = 'html/guidelines.html';
(async () => {
try {
const browser = await puppeteer.launch(configuration);
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' });
const stream = await page.$eval(
'main',
el => el.innerHTML.replace(/\t/g, '')
);
await browser.close();
write(filePath, stream);
} catch (error) {
core.setFailed(`Scraping failed with error ${error}`);
}
})();
function write(filePath, stream) {
try {
fs.writeFileSync(Path.join(__dirname, filePath), stream, { flag: 'w+' });
} catch(error) {
core.setFailed(`Creating file failed with error ${error}`);
}
}