110,566
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
bool isload = false;
public Form1()
{
InitializeComponent();
webBrowser1.Navigate(url1);//第一个页面
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
HtmlElement element = webBrowser1.Document.GetElementById("username");
element.InnerText = "07lls";
element = webBrowser1.Document.GetElementById("password");
element.InnerText = "1";
webBrowser1.Document.GetElementById("image").InvokeMember("Click");
//this.webBrowser1_DocumentCompleted(null ,null);
if (isload)
{
isload = false;
webBrowser1.Navigate(url2);//跳到第二个页面
}
//this.webBrowser1_DocumentCompleted(null, null);
if (isload )
{
isload = false;
HtmlElement temp = webBrowser1.Document.GetElementById("LogonHistory1_dgResult");
//System.Threading.Thread.Sleep(10000);
MessageBox.Show(temp.ToString());
}
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
isload = true;
}
}
}
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll ")]
public static extern System.IntPtr FindWindowEx(System.IntPtr parent, System.IntPtr childe, string strclass, string strname);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
private static extern void SetForegroundWindow(IntPtr hwnd);
const uint BM_CLICK = 0xF5;
//取得消息框的句柄
IntPtr p = FindWindowEx(System.IntPtr.Zero, System.IntPtr.Zero, null, "Choose a digital certificate");
//取得OK按钮的句柄
IntPtr hwndok = FindWindowEx(p, System.IntPtr.Zero, null, "Ok");
//显示到前端
SetForegroundWindow(p);
//模拟点击按钮
SendMessage(hwndok, BM_CLICK, 0, 0);
this.Close();
string Html = "<FONT face=\"宋体\"> <table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"LogonHistory1_dgResult\" style=\"border-width:1px;border-style:solid;font-size:X-Small;width:100%;border-collapse:collapse;\"> <tr class=\"tableTag\" nowrap=\nowrap\" align=\"Center\"> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl0','')\">登录IP </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl1','')\">登录时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl2','')\">登出时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl4','')\">在线时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl5','')\">国内流量 </a> </td> <td nowrap=\nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl6','')\">国际流量 </a> </td> </tr> <tr nowrap=\"nowrap\" align=\"Center\" style=\"background-color:White;height:25px;\"> <td>10.18.2.10 </td> <td nowrap=\"nowrap\" align=\"Left\">2010-1-27 9:15:32 </td> <td nowrap=\"nowrap";
Regex r = new Regex(@"(?is)(?<=<td>)(?:(?!</?/td\b).)*(?=</td>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match m in r.Matches(Html))
{
foreach(Capture c in m.Captures)
{
string IP = c.Value;
}
}
string Html = "<FONT face=\"宋体\"> <table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"LogonHistory1_dgResult\" style=\"border-width:1px;border-style:solid;font-size:X-Small;width:100%;border-collapse:collapse;\"> <tr class=\"tableTag\" nowrap=\nowrap\" align=\"Center\"> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl0','')\">登录IP </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl1','')\">登录时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl2','')\">登出时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl4','')\">在线时间 </a> </td> <td nowrap=\"nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl5','')\">国内流量 </a> </td> <td nowrap=\nowrap\"> <a href=\"javascript:__doPostBack('LogonHistory1$dgResult$_ctl2$_ctl6','')\">国际流量 </a> </td> </tr> <tr nowrap=\"nowrap\" align=\"Center\" style=\"background-color:White;height:25px;\"> <td>10.18.2.10 </td> <td nowrap=\"nowrap\" align=\"Left\">2010-1-27 9:15:32 </td> <td nowrap=\"nowrap";
int count = Html.Length;
int starIndex = Html.IndexOf("<td>", 0, count);
int endIndex = Html.IndexOf("</td>", starIndex, count - starIndex);
string IP = Html.Substring(starIndex+4, endIndex - starIndex-4);