95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
const puppeteer = require('puppeteer');
|
|
const axios = require('axios')
|
|
const path = require('path')
|
|
|
|
const apiKey = "6hUfJdAartHTHhHc0WIRZYPWe"
|
|
// Spark Production ^
|
|
// const apiKey = "p5fidpuedHaOlPnd8EcpxzQMG"
|
|
// Luminate Production ^
|
|
const uid = "/\?uid\=7beg87y4-fh24-4929-3rt5-24kdn87s5241";
|
|
const groupIds = [
|
|
'6cd835d9-ce6e-4ba2-a5b8-8b993d818acf',
|
|
'807048f0-89a0-41e6-a52b-f8d28ad30195'
|
|
]
|
|
|
|
const getAllGroups = async (num) => {
|
|
let i = 0
|
|
loopIds(i)
|
|
}
|
|
|
|
function loopIds(i) {
|
|
console.log("Loop Ids Function")
|
|
var num = 1
|
|
id = groupIds[i]
|
|
courseOverview(id, i, num)
|
|
}
|
|
|
|
async function courseOverview(id, i, num) {
|
|
// console.log("Course Overview Function")
|
|
const activity = new Array();
|
|
const url = "https://walmart.northpass.com/app/courses/";
|
|
const browser = await puppeteer.launch();
|
|
const page = await browser.newPage();
|
|
const course = url+id+uid;
|
|
console.log(course)
|
|
if (course.includes("undefined")) {
|
|
console.log("Error - Undefined UUID. Possibly end of list. Exiting.")
|
|
await browser.close();
|
|
} else {
|
|
await page.setViewport({ width:390, height:844 })
|
|
// await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3419.0 Safari/537.36');
|
|
await page.goto(course, {
|
|
waitUntil: 'load',
|
|
timeout: 0 });
|
|
|
|
await page.title();
|
|
const [getXpath] = await page.$x('/html/body/div[1]/div');
|
|
const resourcetitle = await page.evaluate(name => name.innerText, getXpath);
|
|
// console.log(resourcetitle)
|
|
const resource = resourcetitle.trim();
|
|
console.log(resource);
|
|
|
|
await page.screenshot({path: `${resource}_1.png`, fullPage:true });
|
|
|
|
const hrefs = await page.$$eval('a', as => as.map(a => a.href));
|
|
var links = Object.entries(hrefs);
|
|
// console.log(links)
|
|
links.forEach(([key, value]) => {
|
|
var link = value;
|
|
if (link.includes("activities") && (link.includes(id))) {
|
|
// console.log("Activities Link")
|
|
// console.log(link);
|
|
activity.push(link);
|
|
}
|
|
});
|
|
setTimeout(() => {
|
|
|
|
}, 10000);
|
|
uniqueLinks = [...new Set(activity)];
|
|
for (const link of uniqueLinks) {
|
|
|
|
num = num+1
|
|
const newlink = link+uid;
|
|
console.log("New Link: " + newlink)
|
|
await page.setViewport({ width: 390, height: 844 })
|
|
await page.goto(newlink, {
|
|
waitUntil: 'load',
|
|
timeout: 0 });
|
|
await page.screenshot({path: `${resource}_${num}.png`, fullPage: true });
|
|
screenshots(newlink, resource, num, i);
|
|
}
|
|
await browser.close();
|
|
i++;
|
|
loopIds(i);
|
|
}
|
|
}
|
|
|
|
async function screenshots(newlink, resource, num, i) {
|
|
const browser = await puppeteer.launch();
|
|
const page = await browser.newPage();
|
|
await browser.close();
|
|
}
|
|
|
|
getAllGroups();
|
|
|