1、申 请 I D :jacklp
2、个人邮箱:jacklp1@qq.com
3、原创技术文章: 偶然发现草榴在发码 立即写了一个抢码软件 ,并能自动注册;为了抓紧时间 功能简单;由于已经抢到3个,所以,功能也就没去完善
[C#] 纯文本查看 复制代码 public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("http://ruai.lesile.net/register.php");
}
/// <summary>
/// 获取编码格式
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
public Encoding GetEncoding(HttpWebResponse response)
{
Encoding code = Encoding.Default;
string charset = null;
//如果发现content-type头
string ctypeLower = response.Headers["content-type"];
string ctypeOrder = response.Headers["Content-Type"];
string ctype = "";
if (!ctypeLower.Equals(""))
ctype = ctypeLower;
if (!ctypeOrder.Equals(""))
ctype = ctypeOrder;
//Console.WriteLine("ctype:" + ctype);
if (ctype != null)
{
int ind = ctype.IndexOf("charset=");
if (ind != -1)
{
charset = ctype.ToLower().Substring(ind + 8);
}
}
Console.WriteLine("charset编码格式:" + charset);
if (charset != "")
{
try
{
code = Encoding.GetEncoding(charset);
}
catch { }
}
return code;
}
/// <summary>
/// GET URL
/// </summary>
/// <param name="Url"></param>
/// <returns></returns>
private string GetWebContent(string Url)
{
start:
try
{
string strResult = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 10000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = GetEncoding(response);// 取得要取得的网页的编码方式
//Encoding encoding = Encoding.GetEncoding("utf-8");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
return strResult;
}
catch
{
goto start;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
public string strWeb;
private static string Url = "http://ruai.lesile.net/htm_data/7/1410/1257255.html";
string str = "";
private string strWebContent;
private int iLastStart;
private int iStart;
private int iEnd;
private void reCAOLIU()
{
REtry:
try
{
//得到指定Url的源码
strWebContent = GetWebContent(Url);
//webBrowser2.DocumentText = strWebContent;
iLastStart = strWebContent.IndexOf("第五批", 0);
if (iLastStart == -1)
{
return;
}//获取邀请码
iStart = strWebContent.IndexOf("<br>", iLastStart + 50);
iEnd = strWebContent.IndexOf("<br>", iStart + 6);
strWeb = strWebContent.Substring(iStart + 4, iEnd - iStart - 4);
textBox2.Text = strWeb;
label1.Text = DateTime.Now.TimeOfDay.ToString();
timer1.Enabled = false;
HtmlElement regname = webBrowser1.Document.GetElementById("regname");
HtmlElement regpwd = webBrowser1.Document.GetElementById("regpwd");
HtmlElement regpwdrepeat = webBrowser1.Document.GetElementById("regpwdrepeat");
HtmlElement regemail = webBrowser1.Document.GetElementById("regemail");
HtmlElement invcode = webBrowser1.Document.GetElementById("invcode");
//自动填写注册信息
regname.InnerText = "jacklp";
regpwd.InnerText = "123456";
regpwdrepeat.InnerText = "123456";
regemail.InnerText = "jacklp1@qq.com";
invcode.InnerText = strWeb;
HtmlElement submit = webBrowser1.Document.GetElementById("regsubmit");//提交注册
submit.InvokeMember("click");
}
catch
{
goto REtry;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
reCAOLIU();
}
}
|