A simple voting Robot

Source: Internet
Author: User

Reposted from: www.csdn.net


A simple voting RobotYesterday, I signed up for a friend who took the Japanese proficiency test, but the number of places was full. I had to try again. Manual operations were troublesome, so I decided to try a robot, so I turned out a voting robot last year. (Register for the robot and write another article) at that time, SARS was trapped in the dormitory, and the company that completed the establishment was participating in the selection of one of the top ten emerging technology enterprises, with online voting links. It took a day to develop this small program. After a simple look, the voting page is very amateur. On an ASP page, there is no user registration or IP address restriction, and the voting is completely anonymous. But for the sake of insurance, I still think of a lot of ways, it is very difficult to forge an IP address, I will use a proxy server, use a proxy server to vote in a proxy list, and the probability of selection is not 100%, instead, the voting interval can be adjusted freely. There are several ways to send the voting result: N is to construct a data packet and directly post it. This method was not successful at the time, and there was no reason to go into it. N another way is to automatically enter the form and then submit the result through the form. I am using this method. I used Delphi7 for development and mainly used the twebbrowser control. At that time, I used it for the first time, so now there are many problems. First, a page is dynamically generated: Table 1
Construct the HTML source code:Procedure tfrmmain. makehtml;VaRListstr1, liststr2, checknum1, checknum2: string;Htmlfile: textfile;I, j, WHO, Part1, Part2, num1, probility: integer;BeginListstr1: = '';Liststr2: = '';Htmlbody: = '<HTML> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"> ';Htmlbody: = htmlbody + '<body background = "bgpaper.gif"> <title>Voting System </title> <p align = "center"> & nbsp; </P> '; Htmlbody: = htmlbody + '<input type = hidden name = "linkurl" value = ""> ';Htmlbody: = htmlbody + '<Table width = "80%" align = "center" border = "1" bordercolor = "#339966"> <tr bordercolor = "# ffffff"> ';Htmlbody: = htmlbody + '<TD align = center colspan = 2> ';............//Construct voting options ―――――――――――――――――――――For J: = 1 to 23 doBeginChecklist1 [J]: = false;Checklist2 [J]: = false;End; Randseed: = inttime;Randomize; //Determine whether to select the target option based on the selected voting probability.If factor = 0 thenPart1: = random (10)Else Part1: = random (11 );Num1: = Part1;While (Part1> 0) DoBeginWHO: = random (23) + 1;For J: = 1 to 23 doBeginIf checklist1 [who] ThenBreakElseBeginChecklist1 [who]: = true;Part1: = part1-1;End;End;End; Probility: = random (100) + 1;If factor = 0 thenChecklist2 [2]: = trueElse if (probility mod factor) = 0 thenChecklist2 [2]: = true; If checklist2 [2] ThenPart2: = (10-num1)-1Else Part2: = (10-num1 );While (Part2> 0) DoBeginWHO: = random (23) + 1;For J: = 1 to 23 doBeginIf checklist2 [who] Then //BreakElseBeginChecklist2 [who]: = true;Part2: = part2-1;End;End;End; For J: = 1 to 23 doBeginIf checklist1 [J] ThenBeginListstr1: = liststr1 + checkedlist1 [J];Checknum1: = checknum1 + inttostr (j) + ','; EndElse liststr1: = liststr1 + uncheckedlist1 [J]; If checklist2 [J] ThenBeginListstr2: = liststr2 + checkedlist2 [J];Checknum2: = checknum2 + inttostr (j) + ','; EndElse liststr2: = liststr2 + uncheckedlist2 [J];End;Richedit1.lines. Add (''+ Inttostr (times Div 2) + 1) +'Voting Result :');Richedit1.lines. Add ('The first group selected sequence number ('+ inttostr (num1) +'): '+ Checknum1 );Richedit1.lines. Add ('The second group selected sequence number ('+ inttostr (10-num1) +'): '+ Checknum2 ); Htmlbody: = htmlbody + liststr2;Htmlbody: = htmlbody + '<input type = hidden name = "Choice 2" value = "23"> <tr bgcolor = "# e7e8e3" bordercolor = "# ffffff"> <TD bgcolor = "# cccccc"> <TD align = center> <input name = "sub" type = submit value ="Submit "> </table> </form> </body> End;
Load the generated HTML into webbrowser and generate webpage table 2
Procedure tfrmmain. loadhtml;VaRURL, V: olevariant;Htmldocument: ihtmldocument2;BeginTryMakehtml;ExceptOn E: exception do// Showmessage ('Error! '+ E. Message );// Exit;End; Htmldocument: = (webbrowser1.document as ihtmldocument2 );V: = vararraycreate ([0, 0], varvariant );V [0]: = htmlbody; // here's your HTML stringHtmldocument. Write (psafearray (tvardata (V). varray ));Htmldocument. close;End;
Click the submit button on the webpage to submit the form data: Table 3
Procedure tfrmmain. submitform;VaROBJ: olevariant;DOC: ihtmldocument2;BeginDOC: = (webbrowser1. Document as ihtmldocument2 );If doc <> nil thenBegin// Richedit1.text: = Doc. Body. innertext;OBJ: = Doc. All. Item ('sub', 0 );OBJ. Click;End;End;
Set proxy server: Table 4
Function tfrmcheckproxy. changeproxy (const proxy, port, bypass: string; const benabled: Boolean = true): Boolean;VaRReg: Tregistry;Info: internet_proxy_info;Fproxy: string;BeginResult: = false;Fproxy: = format ('% s: % s', [proxy, port]);Reg: = Tregistry. Create;TryReg. rootkey: = HKEY_CURRENT_USER;If Reg. openkey ('/software/Microsoft/Windows/CurrentVersion/Internet settings', true) thenBeginReg. writestring ('proxyserver', fproxy );Reg. writeinteger ('proxyenable', INTEGER (benabled ));Info. dwaccesstype: = internet_open_type_proxy;Info. lpszproxy: = pchar (proxy );Info. lpszproxybypass: = pchar (bypass );Internetsetoption (nil, internet_option_proxy, @ info, sizeof (Info ));Internetsetoption (nil, internet_option_settings_changed, nil, 0 );// Internetsetoption (nil, internet_option_refresh, nil, 0 );// Sendmessage (hwnd_broadcast, wm_settingchange, 0, 0 );Result: = true;EndFinallyReg. closekey;Reg. Free;End;End;
Last page: Figure 1 Main Page (using a third-party package-suipackage) Chart 2 Chart 1 Main Page, and viewing the voting process and results (using a third-party package-suipackage on the Interface)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.