-1

Conventionally, you can get the HTML of sites with this code But when I want to get the HTML of a Spotify public playlist, I face a problem (the HTML is not received, what's the problem?)

            string HTML = string.Empty;
            using (WebClient WC = new WebClient())
            {
                HTML = WC.DownloadString("https://open.spotify.com/playlist/72Yj5J3f9EfCwbD3MsBX8U");
            }

I know! SpotifyAPI.NET can also be used, but I would like to solve this problem Thank

  • 5
    You DO receive the HTML, which consists of a `
    ` and a number of `
    – Peter B Jul 11 '23 at 19:22
  • 1
    Perhaps you're looking for a "headless browser" or some variant of an in-code browser engine which will also fetch linked resources, execute JavaScript, update the DOM, etc.? Currently all you're doing is making a single HTTP request and receiving a response, which works exactly as it's intended to. – David Jul 11 '23 at 19:24
  • Can you provide an alternative code so that the scripts can be executed so that I can get the full HTML? – BenyaminDev Jul 11 '23 at 19:40
  • @BenyaminDev: Using your favorite search engine to search for "C# headless browser" is a great way to get started. – David Jul 11 '23 at 19:51

1 Answers1

-1

You can try use a request Get,

Example use postman: enter image description here

Code

 var myHeaders = new Headers();
    myHeaders.append("Cookie", "sp_landing=https%3A%2F%2Fopen.spotify.com%2Fplaylist%2F72Yj5J3f9EfCwbD3MsBX8U%3Fsp_cid%3Db7f34d8cef4501007dc3201c9cf647ea%26device%3Ddesktop; sp_t=b7f34d8cef4501007dc3201c9cf647ea");
    
    var requestOptions = {
      method: 'GET',
      headers: myHeaders,
      redirect: 'follow'
    };
    
    fetch("https://open.spotify.com/playlist/72Yj5J3f9EfCwbD3MsBX8U", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));