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);
}