-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASC.js
71 lines (57 loc) · 1.68 KB
/
ASC.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
fs = require("fs")
const webdriver = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');
path = require('path');
var ct = 0;
if (process.argv.length < 3) {
console.log("Pleasae enter filename");
process.exit(1);
}
// Read the file and print its contents.
filename = process.argv[2];
fs.readFile(filename, 'utf8', async function(err, data) {
if (err) throw err;
console.log('OK: ' + filename);
console.log("data "+data)
var newDate = new Date();
let foldName = newDate.getDate()+"_"+newDate.getTime();
fs.mkdir(path.join(__dirname, foldName), (err) => {
if (err) {
return console.error(err);
}
console.log('Directory created successfully!');
});
await func_parse(data,foldName)
});
async function func_parse(data,fold)
{
urls = data.split("\r\n");
for(i=0;i<urls.length;i++)
{
//if(ct == i)
await screenCapture(urls[i],fold)
}
}
async function screenCapture(url,fold)
{
//fs.mkdir();
new_url1 = "https://"+url;
//new_url2 = "http://"+url;
console.log("SC "+ new_url1);
await example(new_url1,fold,url);
}
async function example(url,fold,name) {
let driver = await new Builder()
.forBrowser('chrome')
.build();
await driver.get(url).catch(async (err)=>{
console.log("Error is "+url+" => "+err);
console.log(url+" not found");
// await driver.quit();
})
let encodedString = await driver.takeScreenshot();
let date = new Date();
let time = date.getTime();
await fs.writeFileSync('./'+fold+'/'+name+'.png', encodedString, 'base64');
await driver.quit();
}