让我的应用程序登录网页时出现问题

问题描述 投票:0回答:0

“*”是我登录的凭据,并设置为变量。 当我运行代码时,我的返回值是一个字符串,说明我的条件语句,else 值。 我很确定我的思考方向是正确的,但在我的思考过程中的某个地方它变得混乱了。我希望它是一个简单的修复。 也和我一起裸露我是消防员而不是编码员哈哈

using HtmlAgilityPack;
using System;
using System.Net;

class Program
{
    static void Main(string[] args)
    {
        string url = "https://app.bryx911.com/login";
        string[] keywords = { "M02", "E56", "L25" };
        string username = "**********";
        string password = "*******";

        using (var handler = new HttpClientHandler { CookieContainer = new CookieContainer(), UseCookies = true })
        {
            using (HttpClient client = new HttpClient(handler))
            {
                var loginContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("Email...", username),
                    new KeyValuePair<string, string>("Password...", password)
                });

                var loginResult = client.PostAsync("https://app.bryx911.com/login", loginContent).Result;

                if (loginResult.IsSuccessStatusCode)
                {
                    var responseContent = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;

                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(responseContent);

                    foreach (string keyword in keywords)
                    {
                        if (doc.DocumentNode.InnerText.Contains(keyword))
                        {
                            Console.WriteLine($"Found '{keyword}' on the page.");
                        }
                        else
                        {
                            Console.WriteLine($"Could not find '{keyword}' on the page.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Login failed.");
                }
            }
        }
    }
}


提前谢谢你,非常感谢。

c# web-scraping console-application html-agility-pack httpclienthandler
© www.soinside.com 2019 - 2024. All rights reserved.