C# 打开一个网站URL并使用C中的用户名和密码登录到该网站#

C# 打开一个网站URL并使用C中的用户名和密码登录到该网站#,c#,html,C#,Html,我有一个wpf窗口,里面有一个文本框和一个按钮。我在文本框中手动输入一个网站url(例如www.abc.com/index.html) 此网站页面包含一个登录面板(在正常情况下,用户必须输入用户名和密码才能登录) 我正在寻找一种方法来读取该URL,并通过c#code发送登录凭据,以登录到该站点并读取该特定html页面(登录后的页面)的内容 请帮助我,因为我是新手。有一些web测试工具,比如Selenium(我想就是它的名字),可以很好地做到这一点,但是如果你想让一个穷人(或女人)的方式奏效的话

我有一个wpf窗口,里面有一个文本框和一个按钮。我在文本框中手动输入一个网站url(例如www.abc.com/index.html)

此网站页面包含一个登录面板(在正常情况下,用户必须输入用户名和密码才能登录)

我正在寻找一种方法来读取该URL,并通过c#code发送登录凭据,以登录到该站点并读取该特定html页面(登录后的页面)的内容


请帮助我,因为我是新手。

有一些web测试工具,比如Selenium(我想就是它的名字),可以很好地做到这一点,但是如果你想让一个穷人(或女人)的方式奏效的话

我这样做是为了一个有日终股票数据的网站,我不想每次都登录

我这样做的方式是创建一个Windows窗体应用程序,并在应用程序的主窗体中添加一个全屏BrowserControl。然后添加一系列计时器,计时事件大约6000次(相隔6秒),直到您知道您的积分需要在哪里

在登录屏幕中单击鼠标。你怎么知道点击哪里?试错:

我的Nuget包DataJuggler.Core.UltimateHelper包含一个名为MouseHelper的类

然后你可以打电话:

我为要单击的不同位置定义点

点=新点(120120);//示例:更改您的用户名按钮在表单的WebBrowser控件上的位置

鼠标帮助器。单击(点)

然后键入值:

SendKeys.Send('(YourLogin)'); 
一个计时器的勾号事件完成后,让它启用下一个计时器

我能够改变组合框下拉列表,选择不同的文件下载

这是你可能不应该做的事情之一,但如果你需要一些公开的数据,但不想付费获取,也不想手动下载,这就是我的解决方案

            public void ShowPoint(Point point)
            {
                int y = point.Y;

                for (int x = point.X - 60; x < point.X; x++)
                {
                    this.Cursor = new Cursor(Cursor.Current.Handle);

                    System.Threading.Thread.Sleep(30);

                    Cursor.Position = new Point(x, y);
                    Cursor.Clip = new Rectangle(this.Location, this.Size);    
                }
            }  
public void ShowPoint(点)
{
int y=点y;
对于(int x=point.x-60;x
这种方法可以让人知道你点击的位置。它将放置鼠标并移动光标。你真的不需要它来完成你的应用程序,但是它的设计目的是为了找到你点击的位置

private void DownloadTimer_Tick(object sender, EventArgs e)
            {
                // Increment the value for count
                count++;

                // if the value for count equals 1
                switch (count)
                {

                    case 1:

                        // Go to the EODData website on the Download Tab

                        // Go to the website
                        this.Browser.Navigate(EndOfDayDataUrl);

                        // Reset it, had to give time to login since cookies were cleared
                        this.DownloadTimer.Interval = 60000;

                        // required
                        break;

                    case 2:

                        // Reset it, had to give time to login since cookies were cleared
                        this.DownloadTimer.Interval = 6000;

                        // Move the cursor to the Download Link
                        ShowPoint(DownloadLink);

                        // Click the Download tab
                        MouseHelper.MouseClick(DownloadLink);

                        // required
                        break;

                    case 3:

                        // Show point
                        ShowPoint(CloseSplash);

                        // Close Splash Screen
                        MouseHelper.MouseClick(CloseSplash);

                        // required
                        break;

                    case 4:

                            // Show point
                            ShowPoint(DownloadButtonPoint);

                            // Click the Download button
                            MouseHelper.MouseClick(DownloadButtonPoint);

                            // required
                            break;

                    case 5:

                        // Show point
                        ShowPoint(SaveButtonClick);

                        // Click the Save button 
                        MouseHelper.MouseClick(SaveButtonClick);

                        // required
                        break;

                    case 6:

                        // Show point
                        ShowPoint(SaveFileClick);

                        // Click the Save button for the Save File dialog
                        MouseHelper.MouseClick(SaveFileClick);

                        // required
                        break;

                    case 7:

                        // Show point
                        ShowPoint(OpenDropDown);

                        // Open the Drop Down to select which data to download
                        MouseHelper.MouseClick(OpenDropDown);

                        // required
                        break;

                    case 8:

                        // Show point
                        ShowPoint(SelectAMEX);

                        // Select American Stock Exchange in the Drop Down
                        MouseHelper.MouseClick(SelectAMEX);

                        // required
                        break;

                     case 9:

                            // Show point
                            ShowPoint(DownloadButtonPoint);

                            // Click the Download button
                            MouseHelper.MouseClick(DownloadButtonPoint);

                            // required
                            break;

                    case 10:

                        // Show point
                        ShowPoint(SaveButtonClick);

                        // Click the Save button to launch the Save File dialog
                        MouseHelper.MouseClick(SaveButtonClick);

                        // required
                        break;

                    case 11:

                        // Show point
                        ShowPoint(SaveFileClick);

                        // Click the Save button on the Save File dialog
                        MouseHelper.MouseClick(SaveFileClick);

                        // required
                        break;

                    case 12:

                        // Show point
                        ShowPoint(OpenDropDown);

                        // Open the Drop Down
                        MouseHelper.MouseClick(OpenDropDown);

                        // required
                        break;

                    case 13:

                        // Show point
                        ShowPoint(SelectNASDAQ);

                        // Select NASDAQ
                        MouseHelper.MouseClick(SelectNASDAQ);

                        // required
                        break;

                     case 14:

                            // Show point
                            ShowPoint(DownloadButtonPoint);

                            // Click the Download button
                            MouseHelper.MouseClick(DownloadButtonPoint);

                            // required
                            break;

                    case 15:

                        // Show point
                        ShowPoint(SaveButtonClick);

                        // Click the Save button to launch the Save File dialog
                        MouseHelper.MouseClick(SaveButtonClick);

                        // required
                        break;

                    case 16:

                        // Show point
                        ShowPoint(SaveFileClick);

                        // Click the Save button for the Save File dialog
                        MouseHelper.MouseClick(SaveFileClick);

                        // required
                        break;

                     case 17:

                        // Show point
                        ShowPoint(OpenDropDown);

                        // Open the Drop Down
                        MouseHelper.MouseClick(OpenDropDown);

                        // required
                        break;

                    case 18:

                        // Show point
                        ShowPoint(SelectNYSE);

                        // Select NYSE
                        MouseHelper.MouseClick(SelectNYSE);

                        // required
                        break;

                     case 19:

                            // Show point
                            ShowPoint(DownloadButtonPoint);

                            // Click the Download button
                            MouseHelper.MouseClick(DownloadButtonPoint);

                            // required
                            break;

                    case 20:

                        // Show point
                        ShowPoint(SaveButtonClick);

                        // Click the Save button which will launch the Safe File Dialog
                        MouseHelper.MouseClick(SaveButtonClick);

                        // required
                        break;

                    case 21:

                        // Show point
                        ShowPoint(SaveFileClick);

                        // Click the Save File Dialog
                        MouseHelper.MouseClick(SaveFileClick);

                        // required
                        break;

                    case 22:

                        // Get the files in the documents path
                        List<string> files = FileHelper.GetFiles(DocumentsPath, "", false);

                        // if there are exactly files
                        if ((ListHelper.HasOneOrMoreItems(files)) && (files.Count == 4))
                        {
                            // Start Stock AI Importer
                            System.Diagnostics.Process.Start(StockAIExePath);
                        }

                        // required
                        break;

                     case 23:

                        // Raise the Interval up to 30 seconds
                        this.DownloadTimer.Interval = 15000;

                        // Show point
                        ShowPoint(StartStockAI);

                        // Start Stock AI
                        MouseHelper.MouseClick(StartStockAI);

                        // required
                        break;

                    case 24:

                        // Create a new instance of a 'Gateway' object.
                        Gateway gateway = new Gateway();

                        // Find the Admin object
                        Admin admin = gateway.FindAdmin(1);

                        // if the admin object exists
                        if (NullHelper.Exists(admin)) 
                        {
                            // if not Processing
                            if (!admin.Processing)
                            {
                                // Lower the Interval back to 5 seconds
                                this.DownloadTimer.Interval = 5000;

                                // Show point
                                ShowPoint(CloseStockAIMessageBox);

                                // Close Stock AI Message Box
                                MouseHelper.MouseClick(CloseStockAIMessageBox);
                            }
                            else
                            {
                                // Decrease the value for count so this same number comes up again
                                count--;
                            }
                        }

                        // required
                        break;

                    case 25:

                        // Show point
                        ShowPoint(CloseStockAI);

                        // Close Stock AI
                        MouseHelper.MouseClick(CloseStockAI);

                        // required
                        break;

                     case 26:

                        // Close this program
                        Environment.Exit(0);

                        // required
                        break;
                }
private void DownloadTimer_Tick(对象发送方,事件参数e)
{
//增加count的值
计数++;
//如果count的值等于1
开关(计数)
{
案例1:
//转到“下载”选项卡上的EODData网站
//访问网站
this.Browser.Navigate(EndOfDayDataUrl);
//重置它,必须给时间登录,因为cookies被清除
this.DownloadTimer.Interval=60000;
//必需的
打破
案例2:
//重置它,必须给时间登录,因为cookies被清除
this.DownloadTimer.Interval=6000;
//将光标移动到下载链接
ShowPoint(下载链接);
//单击下载选项卡
MouseHelper.MouseClick(下载链接);
//必需的
打破
案例3:
//显示点
ShowPoint(CloseSplash);
//关闭启动屏幕
MouseHelper.MouseClick(CloseSplash);
//必需的
打破
案例4:
//显示点
显示点(下载按钮点);
//单击下载按钮
MouseHelper.MouseClick(下载按钮点);
//必需的
打破
案例5:
//显示点
显示点(保存按钮单击);
//单击保存按钮
MouseHelper.MouseClick(SaveButtonClick);
//必需的
打破
案例6:
//显示点
显示点(保存文件单击);
//单击“保存文件”对话框的“保存”按钮
MouseHelper.MouseClick(保存文件单击);
//必需的
打破
案例7:
//显示点
ShowPoint(OpenDropDown);
//打开下拉列表以选择要下载的数据
MouseHelper.MouseClick(打开下拉菜单);
//必需的
打破
案例8:
//显示点
ShowPoint(选择美国运通);
//在下拉列表中选择美国证券交易所
MouseHelper.MouseClick(选择美国);
//必需的
打破
案例9:
//显示点
显示点(下载按钮点);
//单击下载按钮
滑鼠助手,滑鼠夹