Open Beastskyler opened 3 years ago
I have started doing it with puppeteer, right now it only does links and still only does 100
const link = "https://www.youtube.com/playlist?list=PLTo6svdhIL1dvXNr1OujUEdRm885KDYoB";
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(link);
await page.setViewport({
width: 1200,
height: 800
});
await page.waitForSelector("a.yt-simple-endpoint.style-scope.ytd-playlist-video-renderer");
const amountOfItems = await page.evaluate(() => {
return document.querySelector("#stats > yt-formatted-string:nth-child(1) > span:nth-child(1)").innerText;
});
const linkList = await page.evaluate(() => {
var arr = [];
// if (amountOfItems <= 100) {
var links = document.querySelectorAll("#content > a.yt-simple-endpoint.style-scope.ytd-playlist-video-renderer");
links.forEach(element => {
var currentLink = element.getAttribute("href");
currentLink = currentLink.substring(0,currentLink.indexOf("&"));
arr.push("https://www.youtube.com" + currentLink);
});
return arr;
// }
});
console.log(linkList);
await browser.close();
})();
Spent so much time, made me realize how much I don't know. Tbh I don't know how I did it, but I got rid of the limit. Someone please fix and make this code better.
` const link = "https://www.youtube.com/playlist?list=PLuxyDVDEQgJXUN-89ChfO3mDtWgPxMaf9"; const puppeteer = require('puppeteer');
(async () => { function delay(time) { return new Promise(function (resolve) { setTimeout(resolve, time) }); }
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(link);
await page.setViewport({
width: 1200,
height: 800
});
const amountOfItems = await page.evaluate(() => {
var num = document.querySelector("#stats > yt-formatted-string:nth-child(1) > span:nth-child(1)").innerText;
if(num.includes(",")){
num = parseInt(num.replace(/,/g, ''), 10);
}
return num;
});
if (amountOfItems > 100) {
var amountOfScrolls = amountOfItems / 100;
for(i = 0; i < amountOfScrolls; i++){
await page.evaluate( () => {
window.scrollBy(0, window.innerHeight * 16);
});
await delay(1500);
}
}
await page.waitForSelector("a.yt-simple-endpoint.style-scope.ytd-playlist-video-renderer");
const linkList = await page.evaluate(() => {
var arr = [];
var links = document.querySelectorAll("#content > a.yt-simple-endpoint.style-scope.ytd-playlist-video-renderer");
links.forEach(element => {
var currentLink = element.getAttribute("href");
currentLink = currentLink.substring(0, currentLink.indexOf("&"));
arr.push("https://www.youtube.com" + currentLink);
});
return arr;
});
console.log(linkList);
console.log(linkList.length);
await browser.close();
})(); `
I have finally started to get back into coding a found out this no longer works.
Running this command adds no urls. I am a little more comfortable coding and would like to try and help, however, I don't know how much help I could be.