public int apply1(int threadNo) { setLogT(threadNo, "step1"); firstpage: setLogT(threadNo, "get first page.."); string respHtml = weLoveYue( threadNo, "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppWelcome.aspx?p=Gta39GFZnstZVCxNVy83zTlkvzrXE95fkjmft28XjNg%3d", "GET", "", true, ""); reg = @"(?<=name=""__EVENTVALIDATION"" id=""__EVENTVALIDATION"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gEventvalidation[threadNo] = ToUrlEncode(myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto firstpage; } reg = @"(?<=id=""__VIEWSTATE"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gViewstate[threadNo] = ToUrlEncode(myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto firstpage; } makeapointment: setLogT(threadNo, "make a pointment.."); respHtml = weLoveYue( threadNo, "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppWelcome.aspx?p=Gta39GFZnstZVCxNVy83zTlkvzrXE95fkjmft28XjNg%3d", "POST", "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppWelcome.aspx?p=Gta39GFZnstZVCxNVy83zTlkvzrXE95fkjmft28XjNg%3d", true, "__EVENTTARGET=ctl00%24plhMain%24lnkSchApp&__EVENTARGUMENT=&__VIEWSTATE=" + gViewstate[threadNo] + "&____Ticket=" + gTicket[threadNo].ToString() + "&__EVENTVALIDATION=" + gEventvalidation[threadNo] ); gTicket[threadNo]++; reg = @"(?<=name=""__EVENTVALIDATION"" id=""__EVENTVALIDATION"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gEventvalidation[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto makeapointment; } reg = @"(?<=id=""__VIEWSTATE"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gViewstate[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto makeapointment; } setLogT(threadNo, "selecting Location: " + gVACity_raw); verification1: ThreadStart starter = delegate { showVerificationCode(respHtml, threadNo); }; new Thread(starter).Start(); while (gVerificationCode[threadNo] == null || gVerificationCode[threadNo] == "") { Thread.Sleep(50); } selectingLocation: respHtml = weLoveYue( threadNo, "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppScheduling.aspx", "POST", "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppWelcome.aspx?p=Gta39GFZnstZVCxNVy83zTlkvzrXE95fkjmft28XjNg%3d", true, "__VIEWSTATE="+gViewstate[threadNo] + "&ctl00%24plhMain%24cboVAC=" + gVACity + "&ctl00%24plhMain%24btnSubmit=%E6%8F%90%E4%BA%A4&ctl00%24plhMain%24hdnValidation1" + "=%E8%AF%B7%E9%80%89%E6%8B%A9%EF%BC%9A&ctl00%24plhMain%24hdnValidation2=%E7%AD%BE%E8%AF%81%E7%94%B3%E8" + "%AF%B7%E4%B8%AD%E5%BF%83&ctl00%24plhMain%24hdnValidation3=%E5%B1%85%E4%BD%8F%E5%9B%BD&____Ticket="+gTicket[threadNo].ToString() + "&__EVENTVALIDATION=" + gEventvalidation[threadNo] + "&ctl00%24plhMain%24mycaptchacontrol1=" + gVerificationCode[threadNo] ); gTicket[threadNo]++; gVerificationCode[threadNo] = "";//不论输入得正确与否, 都需要清空 reg = @"(?<=name=""__EVENTVALIDATION"" id=""__EVENTVALIDATION"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gEventvalidation[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto selectingLocation; } reg = @"(?<=id=""__VIEWSTATE"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gViewstate[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto selectingLocation; } if (respHtml.Contains("Please enter the correct verification code")) { if (gForceToStop) { return -4; } setLogT(threadNo, "验证码错误!请重新输入"); goto verification1; } delegate2 s0 = new delegate2(delegate() { setLogT(threadNo, "submitting the visa type: " + comboBox1.SelectedItem.ToString()); }); textBox1.Invoke(s0); visatype: respHtml = weLoveYue( threadNo, "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppSchedulingGetInfo.aspx", "POST", "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppSchedulingGetInfo.aspx", true, "__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=" + gViewstate[threadNo] +"&ctl00%24plhMain%24tbxNumOfApplicants" +"=1&ctl00%24plhMain%24cboVisaCategory=" + gCategory //13 for general, 17 for working and holiday +"&ctl00%24plhMain%24btnSubmit=%E6%8F%90%E4%BA%A4&ctl00%24plhMain" +"%24hdnValidation1=%E8%AF%B7%E8%BE%93%E5%85%A5%EF%BC%9A&ctl00%24plhMain%24hdnValidation2=%E6%9C%89%E6" +"%95%88%E4%BA%BA%E6%95%B0%E3%80%82&ctl00%24plhMain%24hdnValidation3=%E6%8A%A5%E5%90%8D%E4%BA%BA%E6%95" +"%B0%E5%BF%85%E9%A1%BB%E4%BB%8B%E4%BA%8E1%E5%92%8C++&ctl00%24plhMain%24hdnValidation4=%E7%AD%BE%E8%AF" +"%81%E7%B1%BB%E5%88%AB&____Ticket="+gTicket[threadNo].ToString() + "&__EVENTVALIDATION=" + gEventvalidation[threadNo] ); gTicket[threadNo]++; gVerificationCode[threadNo] = "";//不论输入得正确与否, 都需要清空 if (respHtml.Contains("No date(s) available for appointment.") || respHtml.Contains("无日期(S)委任")) { setLogT(threadNo, "该类别名额已满,不要灰心,备战下一次"); return -9; } reg = @"(?<=name=""__EVENTVALIDATION"" id=""__EVENTVALIDATION"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gEventvalidation[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto visatype; } reg = @"(?<=id=""__VIEWSTATE"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gViewstate[threadNo] = ToUrlEncode( myMatch.Groups[0].Value); } else { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto visatype; } setLogT(threadNo, "filling in email address.."); verification3: starter = delegate { showVerificationCode(respHtml, threadNo); }; new Thread(starter).Start(); while (gVerificationCode[threadNo] == null || gVerificationCode[threadNo] == "") { Thread.Sleep(50); } emailaddress: respHtml = weLoveYue( threadNo, "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/EmailRegistration.aspx", "POST", "https://www.visaservices.in/DIAC-China-Appointment_new/AppScheduling/AppSchedulingGetInfo.aspx", true, "__VIEWSTATE=" + gViewstate[threadNo] + "&__EVENTVALIDATION=" + gEventvalidation[threadNo] + "&ctl00%24plhMain%24txtCnfPassword="******"&ctl00%24plhMain%24txtEmailID=" + gEmail + "&ctl00%24plhMain%24txtPassword="******"&ctl00%24plhMain%24ImageButton1=%E6%8F%90%E4%BA%A4" + "&____Ticket=" + gTicket[threadNo].ToString() + "&ctl00%24plhMain%24mycaptchacontrol1=" + gVerificationCode[threadNo] ); gTicket[threadNo]++; gVerificationCode[threadNo] = "";//不论输入得正确与否, 都需要清空 if (respHtml == "" || String.IsNullOrEmpty(respHtml)) //由于网络原因请求失败 { if (gForceToStop) { return -4; } setLogtRed(threadNo, "getting page failed, retry.."); goto emailaddress; } if (respHtml.Contains("Please enter the correct verification code")) { setLogT(threadNo, "验证码错误!请重新输入"); //因为这是step1的最后一步,所以只有在验证码输错的情况下才需要去获取Viewstate和Eventvalidation reg = @"(?<=name=""__EVENTVALIDATION"" id=""__EVENTVALIDATION"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gEventvalidation[threadNo] = ToUrlEncode(myMatch.Groups[0].Value); } reg = @"(?<=id=""__VIEWSTATE"" value="").*?(?="" />)"; myMatch = (new Regex(reg)).Match(respHtml); if (myMatch.Success) { gViewstate[threadNo] = ToUrlEncode(myMatch.Groups[0].Value); } if (gForceToStop) { return -4; } goto verification3; } else if (respHtml.Contains("请登录您的注册邮箱打开该网址")) { setLogT(threadNo, "邮件已送出, step1 finish"); Mail163 myMail = new Mail163(threadNo, gEmail, emailPassword, this); urlForStep2[threadNo] = myMail.queery("Appointment Registration URL", @"https://www\.visaservices(\s|\S)+?(?=</a>)"); return 1; } else { setLogtRed(threadNo, "未收到邮件送出回执, 仍然尝试接收邮件, 同时请再开软件继续申请"); Thread.Sleep(3000); Mail163 myMail = new Mail163(threadNo, gEmail, emailPassword, this); urlForStep2[threadNo] = myMail.queery("Appointment Registration URL", @"https://www\.visaservices(\s|\S)+?(?=</a>)"); return 1; } return -1; }
//for test private void button2_Click(object sender, EventArgs e) { gForceToStop = false; Thread thread1111 = new System.Threading.Thread( delegate() { //test the email exception gThreadNo++; gViewstate.Add(""); gEventvalidation.Add(""); gVerificationCode.Add(""); gCookieContainer.Add(null); gTicket.Add(1); urlForStep2.Add(""); gHtml.Add(""); Mail163 myMail = new Mail163(0, gEmail, emailPassword, this); urlForStep2[gThreadNo] = myMail.queery("Appointment Registration URL", @"https://www\.visaservices(\s|\S)+?(?=</a>)"); setLogT(-1, urlForStep2[gThreadNo]); apply2(gThreadNo); //test the email exception end }); thread1111.Start(); /* //testWetherThreadUseUnicValue ThreadStart starter = delegate { tB(); }; new Thread(starter).Start(); starter = delegate { tA(); }; new Thread(starter).Start(); //答: 不同线程不会使用独立的类成员 //test TimeSpan DateTime dt1 = Convert.ToDateTime("1996-01-01 00:00:00"); DateTime dt20000101 = Convert.ToDateTime("1997-01-01 00:00:00"); setLogT(-1,(dt1-dt20000101).Days.ToString()); int dd = (dt1 - dt20000101).Days; //正则表达式有另一条规则,比懒惰/贪婪规则的优先级更高:最先开始的匹配拥有最高的优先权 reg = @"(?<=a).*?(?=b)"; myMatch = (new Regex(reg)).Match("aaaaaaaaaaa333b"); if (myMatch.Success) { setLogT( -1, myMatch.Groups[0].Value); } //test string 2 DateTime int year = 2015; string strDt = year.ToString() + "April25"; DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "yyyyMMMMd"; DateTime dt = Convert.ToDateTime(strDt, dtFormat); setLogT(-1,dt.ToString()); reg = @"(?<=style=""color:Black"" title="").*?(?= \d+"")"; myMatch = (new Regex(reg)).Match("ent','5750')\" style=\"color:Black\" title=\"September 29\">29</a></td><td align=\"center\" "); if (myMatch.Success) { setLogT( -1,myMatch.Groups[0].Value); } setLogT(-1,comboBox1.SelectedItem.ToString()); gDays.Add("1 data"); gDays.Add("2 data"); gDays.Add("3 data"); setLogT(-1,gDays.Last()); setLogT(-1,gDays[0]); */ }