title: Login to Scraping Testing Ground website and Scrape html after
body: <p>I am building web scraper and I need to scrape html from website that needs login.</p>
  <p>I tried most of stackoverflow anwsers I didn't find anwser I am looking for. I don't know how to get the result html.</p>
  <pre class="lang-cs prettyprint-override"><code>var baseAddress = new Uri(&quot;http://testing-ground.scraping.pro/login&quot;);
              var cookieContainer = new CookieContainer();
              using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
              using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
              {
                  //usually i make a standard request without authentication, eg: to the home page.
                  //by doing this request you store some initial cookie values, that might be used in the subsequent login request and checked by the server
                  var homePageResult = client.GetAsync(&quot;/login&quot;);
                  homePageResult.Result.EnsureSuccessStatusCode();
  
                  var content = new FormUrlEncodedContent(new[]
                  {
                      //the name of the form values must be the name of &lt;input /&gt; tags of the login form, in this case the tag is &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;
                      new KeyValuePair&lt;string, string&gt;(&quot;usr&quot;, &quot;admin&quot;),
                      new KeyValuePair&lt;string, string&gt;(&quot;pwd&quot;, &quot;12345&quot;),
                  });               
                  var loginResult = client.PostAsync(&quot;/login&quot;, content).Result;
                  loginResult.EnsureSuccessStatusCode();
                  Console.WriteLine(loginResult);
  </code></pre>
  <p>I expect the <code>loginResult</code> to be successfull only if</p>
  <blockquote>
  <p>usr is admin</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>pwd is 12345</p>
  </blockquote>
  <p>but no matter what it is positive. Also my main goal is to scrape the result HTML so in this case it should scrape HTML that doesn't have login form, but instead welcome text.</p>