Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
Empty array when trying to scrape YouTube main page with Node.js

so I'm playing around with request and cheerio npm's and I can't seem to find a solution, why does it keep giving me empty arrays. I used same code when I scraped reddit and it worked like a charm, but when I use it on YouTube or any other page it doesn't work.

var request = require('request'),
cheerio = require('cheerio'),
fs = require('fs'),
urls = [];

request('https://www.youtube.com/', function(err,resp,body) {
    if(!err && resp.statusCode == 200) {
        var $ = cheerio.load(body);
        $('a.yt-simple-endpoint style-scope ytd-grid-video-renderer', 'primary').each(function() {
            var url = $(this);
            urls.push(url);
    });

And this is my reddit code (works fine)

var request = require('request'),
cheerio = require('cheerio'),
fs = require('fs'),
urls = [];

request('http://www.reddit.com/', function(err,resp,body) {
    if(!err && resp.statusCode == 200) {
        var $ = cheerio.load(body);
        $('a.title', '#siteTable').each(function() {
            var url = $(this).attr('href');
            if(url.indexOf('imgur.com')!= -1) {
                urls.push(url);
            }
        });

    Output Example: [ 'http://i.imgur.com/WVrmZ9j.gifv',
  'http://i.imgur.com/T0BchYC.gifv',
  'http://imgur.com/u59lzux' ]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The HTML that cheerio loads for youtube is different.

Do res.send($.html()); to check the HTML structure and target it accordingly.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!