mikebruggs
09/04/2024, 4:26 AMDefault handler triggered for: ${request.url});
// Wait for the page to fully load
await page.waitForSelector('ytd-watch-flexy', { timeout: 10000 }); // Adjust the selector and timeout as necessary
log.info(Page is ready for processing: ${request.url});
// Execute JS in the page context to find the caption URL
const captionUrl = await page.evaluate(() => {
const scripts = Array.from(document.querySelectorAll('script'));
for (const script of scripts) {
const match = script.textContent?.match(/https:\/\/www\.youtube\.com\/api\/timedtext\?[^"]+/);
if (match) {
return match[0];
}
}
return null;
});
if (captionUrl) {
log.info(Found caption URL: ${captionUrl});
await Dataset.pushData({
url: request.loadedUrl,
title: await page.title(),
captionUrl,
});
} else {
log.warning(No caption URL found on ${request.loadedUrl});
}
});Hall
09/04/2024, 4:26 AMjosejet
09/05/2024, 9:10 AMjavascript
// await page.waitForSelector('ytd-watch-flexy', { timeout: 10000 }); // Adjust the selector and timeout as necessary
console.log(`Page is ready for processing:`);
console.log("fdsfds");
// Execute JS in the page context to find the caption URL
const captionUrl = await page.evaluate(() => {
const scripts = Array.from(document.querySelectorAll('script'));
for (const script of scripts) {
const match = script.textContent?.match(/https:\/\/www.youtube.com\/api\/timedtext?[^"]+/);
if (match) {
return match[0];
}
}
return null;
});
console.log("fdsfds", captionUrl);
if (captionUrl) {
console.log(`Found caption URL: ${captionUrl}`);
console.log("jhdgfjdfdsfds");
console.log({
url: request.loadedUrl,
title: await page.title(),
captionUrl,
});
console.log("g7fd8sgfdsfds");
} else {
console.log(`No caption URL found on ${request.loadedUrl}`);
}
In my Puppeteer extension and it woked wellkaramelo_51108
09/09/2024, 1:18 PM