我正在尝试创建一个C# Winforms应用程序,它将自动将我登录到一个站点并下载数据。具体地说,我想让我的应用程序自动登录到我的在线银行站点,让我登录,并下载我的交易历史记录。我可以通过web浏览器登录并下载它来手动完成此操作。我正在尝试自动化这一点。我知道我可能需要使用HttpWebRequest和HttpWebResponse。有没有人有这样的例子,或者我需要采取的步骤的框架?请记住,它将是安全站点(https),我将不得不以某种方式收集会话信息,并在会话期间保留会话信息。有什么想法吗?
发布于 2010-05-27 06:10:13
看一下Selenium,您可以使用它自动执行用户和浏览器之间的一系列交互。
你可能很幸运,能够使用web请求和响应登录,尽管许多银行正在转向基于javascript的登录表单来混淆密码,以防止特洛伊木马程序。参见Citibank (AU)和Westpac (AU)。您可能需要手动登录并使用GreaseMonkey脚本自动下载,这一点很难绕过。
出于兴趣,也值得研究一下银行特洛伊木马程序,以及它们如何代表用户处理自动操作。参见Zeus Banking Trojan。
发布于 2010-05-27 06:04:20
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace testSSL
{
public partial class FormDownload : Form
{
private bool success;
private const string filename = "file.txt";
private const string url_string = "https://some.url.com";
private Uri url;
public FormDownload()
{
InitializeComponent();
success = false;
url = new Uri(url_string);
}
public bool StartDownload()
{
this.ShowDialog();
return success;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Activate();
progressBar1.Maximum = 100;
label1.Text = "Working";
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
//possible fix for running on w2k
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
string user="user", pass="pass";
client.Credentials = new NetworkCredential(user, pass);
try
{
client.DownloadFileAsync(url, filename);
}
catch (Exception ue)
{
writeException(ue.Message);
}
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
writeException(e.Error.Message);
success = false;
}
else
{
label1.Text = "Done";
System.Threading.Thread.Sleep(100);
success = true;
}
this.Close();
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void writeException(string ex)
{
ex = "Date: " + DateTime.Now.ToString() + " Exception: " + ex + "\r\n";
File.AppendAllText("downloadLog.txt", ex);
MessageBox.Show("An error has occurred; it has been logged");
this.Close();
}
}}
发布于 2010-05-29 05:45:07
请查看Open Financial Exchange规范。这就是Quicken/Money等从你的金融机构下载交易的方式。
https://stackoverflow.com/questions/2917126
复制相似问题