Finalized WALMART screenshots! Maybe It can be productized.
This commit is contained in:
109
Scripts/Walmart_Screenshots/resources_api.js
Normal file
109
Scripts/Walmart_Screenshots/resources_api.js
Normal file
@ -0,0 +1,109 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
const axios = require('axios')
|
||||
const path = require('path')
|
||||
|
||||
const apiKey = "6hUfJdAartHTHhHc0WIRZYPWe"
|
||||
const uid = "/\?uid\=7b84eae4-fb34-4689-9f33-24071c3e5a41";
|
||||
const groupIds = []
|
||||
|
||||
const getAllGroups = async (num) => {
|
||||
if(num === 1){
|
||||
}
|
||||
|
||||
let page = num;
|
||||
|
||||
await axios({
|
||||
method: 'get',
|
||||
url: `https://api.northpass.com/v2/courses?page=${page}&limit=100`,
|
||||
headers: {
|
||||
'accept': '*/*',
|
||||
'x-api-key': apiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.data.links.next != null) {
|
||||
page++;
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
if (res.data.data[i].attributes.status == "live") {
|
||||
groupIds.push(res.data.data[i].id)
|
||||
}
|
||||
}
|
||||
await getAllGroups(page);
|
||||
} else {
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
if (res.data.data[i].attributes.status == "live") {
|
||||
groupIds.push(res.data.data[i].id)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
let i = 0
|
||||
loopIds(i)
|
||||
console.log(groupIds)
|
||||
}
|
||||
|
||||
function loopIds(i) {
|
||||
var num = 1
|
||||
id = groupIds[i]
|
||||
courseOverview(id, i, num)
|
||||
}
|
||||
|
||||
async function courseOverview(id, i, num) {
|
||||
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)
|
||||
await page.setViewport({ width:390, height:844 })
|
||||
await page.goto(course, {
|
||||
waitUntil: 'load',
|
||||
timeout: 0 });
|
||||
|
||||
await page.title();
|
||||
const [getXpath] = await page.$x('/html/body/div[2]/div/div');
|
||||
const resourcetitle = await page.evaluate(name => name.innerText, getXpath);
|
||||
const resource = resourcetitle.trim();
|
||||
console.log(resource);
|
||||
|
||||
await page.screenshot({path: `${resource}_1.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") && (link.includes(id))) {
|
||||
console.log(link);
|
||||
activity.push(link);
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
|
||||
}, 5000);
|
||||
uniqueLinks = [...new Set(activity)];
|
||||
for (const link of uniqueLinks) {
|
||||
num = num+1
|
||||
const newlink = link+uid;
|
||||
await page.setViewport({ width: 390, height: 844 })
|
||||
await page.goto(newlink, {
|
||||
waitUntil: 'load',
|
||||
timeout: 0 });
|
||||
await page.screenshot({path: `${resource}_${num}.png`, fullPage: true, headless: false});
|
||||
//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();
|
||||
Reference in New Issue
Block a user