mardi 1 décembre 2020

Authentication option for web scraping with login in C#

I would like to make a data scraper for this website. https://pokec-sklo.azet.sk/miestnost/9/?i9=587715b09310

I want to get past the authentication to get to the html data. I tried using simple tutorials to pass header but it doesn't work. I do not know which method is used for authentication. I searched for cookies but I do not know which cookie has the correct value because their names are hashed like this: TSae50d7c2027 and the value is: 08a4477ee0ab20002461e19421580d70ce83584f5bad2d45d478afb73d8d5dbfe282495a11ddb6c008f2ed7bdc113000ca2bae70e65d8a6b68f01caefa384cb4ee5c7f166b25b2987431004d247ff8e8d7e9fa96f07f9c0144304aa3f9c5133f

I tested with my credentials and posting it to the login page with C# console application and HttpClient. Here is my code:

static void Main(string[] args) {
            var url = "https://pokec.azet.sk/?force_login=1&uri=https%3A%2F%2Fpokec-sklo.azet.sk%2Fmiestnost%2F9%2F%3Fi9%3D587715b09310";
            HttpClient client = new HttpClient();
            try {
                var content = new FormUrlEncodedContent(new[] {
                    new KeyValuePair<string, string>("username", "username"),
                    new KeyValuePair<string, string>("password", "password")
                });
                var loginResult = client.PostAsync(url, content).Result;
                string responseBody = client.GetStringAsync(url).Result;
                Console.WriteLine(responseBody);
            }
            catch (HttpRequestException e) {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }
            Console.ReadLine();
        }

loginResult gives me 200 http OK response but I still do not get authenticated to view my html data.




Aucun commentaire:

Enregistrer un commentaire