Download Instagram reels by scraping using NodeJS.
An overview of my 2023 walkthrough for extracting an Instagram reel’s video URL with Puppeteer and Cheerio.
The original approach combines browser rendering with HTML parsing. Puppeteer runs the page’s JavaScript; Cheerio reads the resulting markup.
Render the page
Install the two packages, launch a headless browser, and navigate to the reel. Wait for the video element before reading the HTML with page.content(). A simple HTTP request misses the video element when it is added by JavaScript.
npm install puppeteer cheerio
Extract the video URL
Load the rendered HTML into Cheerio, find the video element, and read its src attribute. The result is the direct video URL. Close the page and browser after collecting the HTML.
const $ = cheerio.load(html);
const videoDirectLink = $('video').attr('src');