Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
How to scrape between two (2) dates in time // How to convert Channel and Video ID into URL in script

FYI I have not written this code myself, I've sourced it online via forums like this since it does the job in needs to up to a certain point.

I'm looking to scrape YouTube search results data based on keywords between two dates in time, for example; September 19th - October 4th.

What code and where can I add this to the script?

Here is the script I'm currently using:

function YoutubeScraper() {
  var spreadSheet = SpreadsheetApp.getActiveSpreadsheet()
  var activeSheet = spreadSheet.getActiveSheet();

  // Retrieve YouTube.Search.list.
  var search = YouTube.Search.list("snippet", { q: "Gang Beasts", maxResults: 10 });
  var results = search.items.map((item) => [item.snippet.channelId, item.id.videoId, item.snippet.title, item.snippet.publishedAt]);
  
  // Retrieve channel IDs and video IDs.
  var {channelIds, videoIds} = results.reduce((o, [channelId, videoId]) => {
    o.channelIds.push(channelId);
    o.videoIds.push(videoId);
    return o;
  }, {channelIds: [], videoIds: []});

  // Retrieve YouTube.Videos.list.
  var videoList = YouTube.Videos.list("statistics", {id: videoIds.join(",")});
  var videoStats = videoList.items.map((item) => [item.id, item.statistics.viewCount, item.statistics.likeCount, item.statistics.dislikeCount]).reduce((o, [id, ...v]) => Object.assign(o, {[id]: v}), {});

  // Retrieve YouTube.Channels.list
  var channelList = YouTube.Channels.list("statistics", { id: channelIds.join(",") });
  var channelStats = channelList.items.map((item) => [item.id, item.statistics.subscriberCount]).reduce((o, [id, ...v]) => Object.assign(o, {[id]: v}), {});

  // Create an array for putting values and put the values to Spreadsheet.
  results = results.map(e => channelStats[e[0]] ? e.concat(channelStats[e[0]]) : e.concat(Array(2).fill("")));
  results = results.map(e => videoStats[e[1]] ? e.concat(videoStats[e[1]]) : e.concat(Array(3).fill("")));
  activeSheet.getRange(2, 1, results.length, results[0].length).setValues(results);
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda