0

learning a bit about web interacting with C#. Need to go to the website www.darkorbit.com, login with username/password, and get the value of a span with a specific ID on the in-logged user page.

  1. I tried using HtmlAgilityPack, but it doesn't have an option to submit the login form and proceed to the in-logged user page.

  2. I have completed this using the web client, but the consumption of the RAM is critical, therefore I believe using HttpWebRequest would be the best solution, although I have no clue how to do it, and I haven't found any similar solutions on the web..

2 Answers2

1

Parse the html login page to find the form that has the login input (e.g.name="loginForm") and take that form's action url.

<form name="loginForm" method="post" action="https://someposturl.com">

Then once you have the action url you can send a Post with the form's input as content.

string formActionUrl = @"https://someposturl.com";

var formInputData = new Dictionary<string, string>
{
    { "input1", "hello" },
    { "input2", "world" }
};      

using (var client = new System.Net.Http.HttpClient())
{
    var content = new FormUrlEncodedContent(formInputData);

    var response = client.PostAsync(formActionUrl, content).Result;

    var responseHtmlString = response.Content.ReadAsStringAsync().Result;
}

With the logged-in responseHtmlString you can parse it to find the span value with the specific Id you are looking for.

Look at this question for Html parsers. For a Html Parser performance comparison look here.

stomtech
  • 454
  • 4
  • 10
  • **DISCLAIMER**: The information provided in this answer is to be used in a legal way only. Any actions or activities related to the material contained in this answer is solely your responsibility. – stomtech Jul 09 '17 at 23:01
  • @Omnitored : Did this answer help you? If it did please accept it as answer or vote for it. – stomtech Jul 11 '17 at 18:00
0

Use selenium . You can use Chrome web driver. Navigate to login url. Find inputs for username/password sendkeys click login button and then navigate to page witchever is required and get any element you want.

This is the easiest way i could suggest.

Mudasir Younas
  • 864
  • 6
  • 10
  • Selenium is the webdriver which let you use browser remotly. – Mudasir Younas Jul 09 '17 at 21:50
  • As I stated above, I need it to run on as little RAM as possible. Running chrome in background won't solve this, don't you think?.. –  Jul 09 '17 at 21:54
  • Two weeks ago i had same problem best solution was HttpWebRequest. But due to lack of documents i could not solve it. So i used Selenium. – Mudasir Younas Jul 09 '17 at 22:03