Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda