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

240
Visualizações
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 à 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