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

241
Vistas
How to get the first video from a youtube search in javascript

Soo i've already seen some ways for doing it with youtube api but for some reason it didn't work. And i had a project that i was working on that the does exactly what i want in python So I tried to "translate it" to javascript but i didn't an equivilant for urllib.request.urlopen that works for js
here is the part of the python code that i want to "translate"

formated_txt = keyword.replace(" ", "+")
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=official+audio+" + formated_txt)#<<<searching for the equivalent for this line
print(html)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
link = "https://www.youtube.com/watch?v=" + video_ids[0]

and this is where i'm at in js

function search() {
    var searchbox = document.getElementById("search");
    searchbox.select();
    searchbox.setSelectionRange(0, 99999);
    var text = searchbox.value.toLowerCase();
    var formated_text = text.split(" ").join("+");
    var link = 'https://www.youtube.com/results?search_query='+formated_text
}

i found that there is urllib module for js but it's not working or i did something wrong

function search() {
    var searchbox = document.getElementById("search");
    searchbox.select();
    searchbox.setSelectionRange(0, 99999);
    var text = searchbox.value.toLowerCase();
    var formated_text = text.split(" ").join("+");
    var link = 'https://www.youtube.com/results?search_query='+formated_text

    const { data, res } = await request(link, {
        method: 'GET',
        data: {}
      });
    // result: { data: Buffer, res: Response }
    console.log('status: %s, body size: %d, headers: %j', res.statusCode, data.length, res.headers);
}
about 4 years ago · Santiago Trujillo
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