2016-05-23 28 views
2

私はpluralsightのようないくつかのhtmlサイトを解析したいと思っていますが、Forexample(https://app.pluralsight.com/id?)だからどうすれば最初にWebブラウザにログインして別のURL(例:Pluralsight)を呼び出してHtmlagility pack 。HttpWebRequestを使用してHttps Webサイトにログインした後のHtmlagilitypack?

しかし、私はログインコードを書いていますが、次のステップはわかりません。

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) 
     { 
      //but I do not know the next step. 
     } 
    } 
} 

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

答えて

0

あなたはHttpWebResponse.GetResponseStreamを経由して、応答のためのストリームを取得し、その後のHTMLDocumentのLoadメソッドを介してドキュメントをロードする必要があります。

var doc = new HtmlAgilityPack.HtmlDocument(); 
doc.Load(response.GetResponseStream()); 
//further processing... 
+0

しかし、私は、送信する別の要求、例えば別のURL(アドレスしたい:https://app.pluralsight.com/library/courses/object-oriented-programming-fundamentals-csharp/table-of-をコンテンツ)を取得し、応答を取得し、Htmlagilityパックを解析します。 – Matteo

関連する問題