Created
April 6, 2021 14:27
-
-
Save vexdy/5c0d4cac66462a7c5201152fe427847a to your computer and use it in GitHub Desktop.
Find youtube channel ID with regex in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'); | |
const regex = /<link rel="canonical" href="(https?:\/\/)?(www\.)?youtube\.com\/(channel|user)\/[\w-]+">/g | |
fetch('https://www.youtube.com/channel/UCa10nxShhzNrCE1o2ZOPztg') | |
.then(res => res.text()) | |
.then(body => console.log(body.match(regex)[0].split(" ")[2].replace('href=\"', '').replace('\">', '').split("/")[4])) | |
// Expected output: | |
// UCa10nxShhzNrCE1o2ZOPztg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment