I want to parse some html site like pluralsight,Forexample (https://app.pluralsight.com/id?), So How can I first login site programmaticaly (without using webbrowser control) then call another url (for example : https://app.pluralsight.com/library/courses/object-oriented-programming-fundamentals-csharp/table-of-contents) and get response and parse with Htmlagility pack.
But I've written a login code, but I do not know the next step.
- public class Login
- {
- private CookieContainer Cookies = new CookieContainer();
-
-
-
- public void SiteLogin(string username, string password)
- {
- Uri site = new Uri("https://app.pluralsight.com/id?");
-
- HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(site);
- wr.Method = "Post";
- wr.ContentType = "application/x-www-form-urlencoded";
- wr.Referer = "https://app.pluralsight.com/id?";
- wr.CookieContainer = Cookies;
- var parameters = new Dictionary<string, string>{
- {"realm", "vzw"},
- {"goto",""},
- {"gotoOnFail",""},
- {"gx_charset", "UTF-8"},
- {"rememberUserNameCheckBoxExists","Y"},
- {"IDToken1", username},
- {"IDToken2", password}
- };
-
- string input = string.Empty;
- using (var requestStream = wr.GetRequestStream())
- using (var writer = new StreamWriter(requestStream, Encoding.UTF8))
- writer.Write(ParamsToFormEncoded(parameters));
-
- using (var response = (HttpWebResponse)wr.GetResponse())
- {
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
-
- }
- }
- }
-
- private string ParamsToFormEncoded(Dictionary<string, string> parameters)
- {
- return string.Join("&", parameters.Select(kvp => Uri.EscapeDataString(kvp.Key).Replace("%20", "+")
- + "=" + Uri.EscapeDataString(kvp.Value).Replace("20%", "+")
- ).ToArray());
- }
- }