0

I am trying to make a small app that can log in automatically on a website, get certain texts on the website and return to user.

To show what I have, I did below to make it log in,

System.Windows.Forms.HtmlDocument doc = logger.Document as System.Windows.Forms.HtmlDocument;

        try
        {
            doc.GetElementById("loginUsername").SetAttribute("value", "myusername");
            doc.GetElementById("loginPassword").SetAttribute("value", "mypassword");
            doc.GetElementById("loginSubmit").InvokeMember("click");

And below to load html of the page

        WebClient myClient = new WebClient();
        Stream response = myClient.OpenRead(webbrowser.Url);
        StreamReader reader = new StreamReader(response);
        string src = reader.ReadToEnd(); // finally reading html and saving in variable

Now, it successfully loaded html but html of the page where it's not logged in. Is there a way to refer to current html somehow? Or another way to achieve my goals. Thank you for reading!

Jack J
  • 67
  • 1
  • 9

2 Answers2

0

Use the Webclient class so you can use sessions and cookies.

check this Q&A: Using WebClient or WebRequest to login to a website and access data

Community
  • 1
  • 1
jh.edens
  • 31
  • 5
0

Why don't you make REST API calls and send the data like username and password from your code itself? Is there any Web API for the URL ? If yes , you can simply call the service and pass on the required parameters. The API shall return in JSON/XML which you can parse and extract information

Apoorv
  • 2,023
  • 1
  • 19
  • 42