Files
Gainsight/Scripts/Walmart_Screenshots/resources.js

65 lines
1.8 KiB
JavaScript

const puppeteer = require('puppeteer');
const path = require('path')
// const urls = [...]
/*for (let i=0; i<urls.length; i++){
const url = urls[i];
await page.goto('${url}');
await page.waitForNavigation({ waitUntil: 'networkkidle2' });
}*/
const url = process.argv[2];
if (!url) {
throw "Please provide a URL as the first argument";
}
const activity = new Array();
const activityLinks = new Array();
var num = 0
async function courseOverview() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width:390, height:844 })
await page.goto(url);
await page.title();
const [getXpath] = await page.$x('//*[@id="course-desktop"]/div/div[3]/div[2]/div[2]/div[2]/ol/li/div');
const resourcetitle = await page.evaluate(name => name.innerText, getXpath);
const resource = resourcetitle.trim();
console.log(resource);
await page.screenshot({path: `${resource}.png`, fullPage:true, headless:false});
const hrefs = await page.$$eval('a', as => as.map(a => a.href));
var links = Object.entries(hrefs);
links.forEach(([key, value]) => {
var link = value;
if (link.includes("activities")) {
activity.push(link);
}
});
uniqueLinks = [...new Set(activity)];
for (const link of uniqueLinks) {
num = num+1
let uid = "?uid\=7b84eae4-fb34-4689-9f33-24071c3e5a41"
const newlink = link+uid;
console.log(newlink)
screenshots(newlink, resource, num);
}
await browser.close();
}
async function screenshots(newlink, resource, num) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 390, height: 844 })
await page.goto(newlink);
await page.screenshot({path: `${resource}_${num}.png`, fullPage: true, headless: false});
await browser.close();
}
courseOverview();