使用WebBrowser编写广告挂机程序
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("userinfo.xml");
if (xmlDoc != null)
{
XmlNode root = xmlDoc.SelectSingleNode("userinfo");
string userid = root.ChildNodes[0].InnerText;
string pwd = root.ChildNodes[1].InnerText;
this.textBoxUserid.Text = userid;
this.textBoxPwd.Text = pwd;
}
else
{
MessageBox.Show("XML文件读取错误!");
}
string userid = this.textBoxUserid.Text;
string pwd = this.textBoxPwd.Text;
xmlDoc.Load("userinfo.xml");
if (xmlDoc != null)
{
XmlNode root = xmlDoc.SelectSingleNode("userinfo");
root.ChildNodes[0].InnerText = userid;
xmlDoc.Save("userinfo.xml");
}
else
{
MessageBox.Show("XML文件写入错误!");
}
string url=this.webBrowser.Url.ToString();
HtmlDocument HTMLDocument = this.webBrowser.Document;
if (url.IndexOf("surf.php") > 0)
{
lblCount.Visible = true;
lblTime.Visible = true;
labelCount.Visible = true;
labelTime.Visible = true;
HtmlElementCollection all = HTMLDocument.All;
int k = 0;
for (int i = 0; i < all.Count; i++)
{
HtmlElement elem = all[i];
if (elem.TagName.ToLower() == "a")
{
this.lblCount.Text = k.ToString();
string anchorString = elem.OuterHtml;
if (anchorString.IndexOf("?ad=") > 0)
{
k++;
anchorString = anchorString.Substring(anchorString.IndexOf("?ad=")+4, 5);
string newUrl = "http://www.bux.to/view.php?ad=" + anchorString;
this.webBrowser.Navigate(newUrl);
}
}
}
}
else if (url.IndexOf("view.php") > 0)
{
this.webBrowser.Stop();
this.timerClock.Enabled = true;
}
else if (url.IndexOf("login.php") > 0)
{
string userid = this.textBoxUserid.Text;
string pwd = this.textBoxPwd.Text;
{
MessageBox.Show("请先打开一个要分析的网页");
return;
}
HtmlElement tbUserid = this.webBrowser.Document.All["COOKIEusername"];
HtmlElement tbPasswd = this.webBrowser.Document.All["COOKIEpass"];
tbUserid.SetAttribute("value", userid);
tbPasswd.SetAttribute("value", pwd);
}
private int startTime=35;
private void timerClock_Tick(object sender, EventArgs e)
{
if (startTime != 0)
{
startTime--;
this.lblTime.Text = startTime.ToString();
}
else
{
this.timerClock.Enabled = false;
startTime = 35;
this.webBrowser.Navigate("http://www.bux.to/surf.php");
}
}
本文出自 “Running...” 博客,请务必保留此出处http://ssbird.blog.51cto.com/277690/58267