Home > front end >  How to download a youtube page in a specific language
How to download a youtube page in a specific language

Time:08-21

I need to get information about video removal reason, and from what I've searched the only way is to get it by scrapping the video page directly (youtube api doesn't seem to provide that information).

But this code:

using (WebClient client = new WebClient())
{
    string htmlCode = client.DownloadString("https://www.youtube.com/watch?v=ZmrrIIhtY7w");
}

returns a page in a language specific to your location, and I would want it to always return the page in english.

I don't really have any idea how to get it, besides using a VPN. I've tried searching for some API that could download web pages, like for example this site does, but couldn't find anything.

Ps. Any library or solution will do fine, as long as it works.

CodePudding user response:

When requesting the YouTube webpage for ZmrrIIhtY7w you need to precise as a cookie PREF=hl=en to get the webpage in English.

You can make sure that it works by testing with curl:

curl 'https://www.youtube.com/watch?v=ZmrrIIhtY7w' -H 'Cookie: PREF=hl=en'
  • Related