Technical points of forum water filling machine 10.06.2004 |
I originally thought that edit, memo, etc. in the web page are the same as those in the program and can be controlled with handles, but later I realized that there is no handle! After checking for a long time, I saw an example about automatic QQ application a few days ago. It mainly controls various operations on the web page! I summarized it and made a forum watering machine: First, you need to reference the mshtml unit in uses. The code and analysis are as follows: var hform:IHTMLFormelement; hdoc:ihtmldocument2; hall:ihtmlelementcollection; Hinput:IHTMLinputelement; iw:iwebrowser2; hlen,tmploop:integer; vk:oleVariant; dispatch:IDispatch; Begin if Assigned(webbrowse1) then /// Ensure that there is content in the web page; that is, a web page has been opened! Begin hdoc:=webbrowse1.document as ihtmldocument2; hall:=hdoc.get_all; hlen:=hall.get_length; ////The above steps are: assign the content in the browser control to hdoc. Take all its identifiers and calculate the total number; ////The following operation is: loop through the total number to find the edit of the user name and password; and assign a value; for tmploop:=0 to hlen-1 do Begin vk:=tmploop; dispatch:=hall.item(vk,0); if succeeded(Dispatch.QueryInterface(IHTMLInputelement,hinput)) then ///If this identifier is an edit control... begin ////The uppercase below is required! Prevent errors in judgment due to different cases! ///The "TEXT" below is determined by the content on the web page. That is to say, if you want to make a judgment, you must use the specific web page code! ///The password box and username are the same! if uppercase(hinput.Type_)='TEXT' then hinput.value:='tress' else if uppercase(hinput.type_)='PASSWord' then hinput.value:='tress'; end; if succeeded(dispatch.QueryInterface(IHTMLFormElement,hform)) and (uppercase(hform.name)='THEFORM') then ///This is the form submission. If you find that there is only one form from the html, then the second condition is non-essential! ///And it is not necessary to judge the name attribute, but it can also be judged based on other attributes. Hform.submit; end; ////for end; end; //if end; end; At this point, an example of automatic login is ready. If you want to implement watering, you can change hinput:ihtmlinputelement to htext:ihtmltextareaelement, which is equivalent to the memo control. Change the assignment of the username to the speech. Just assign values; of course, you can also change it to other things here, such as single choice, etc. For specific content, you can check the list in mshtml! It was enough here. But later I found out that there was a framework in the forum - frame. I was troubled by this for a long time. Later, I asked on csdn, and someone gave a solution and tried it. very nice! You can add it to the above code: var ...... ...... iw:iwebrowser2; Begin ..... iw:=getframe(3); //This step is to obtain the second framework in webbrowse; ///The subsequent operations are the same, that is, the function of the above operations is to process the content in a framework as a web page; hdoc:=iw.document as ihtmldocument2; hall:=hdoc.get_all; ...... ...... ///The getframe() function is as follows and needs to add activex units to the uses: Function TFrmain.GetFrame(FrameNo:Integer):IWebbrowser2; var OleContainer:IOleContainer; enum:IEnumUnknown; unk:IUnknown; Fetched:PLongint; Begin while webbrowse1.ReadyState<>READYSTATE_COMPLETE do application.PRocessMessages; if Assigned(webrowse.document) then Begin Fetched:=nil; OleContainer:=webbrowse.Document as IOleContainer; OleContainer.EnumObjects(OLECONTF_EMBEDDINGS,enum); Enum.Skip(FrameNo); Enum.Next(OLECONTF_EMBEDDINGS,Unk,Fetched); Result:=Unk as IWebbrowser2; end else Result:=nil; end; Another point to be explained is the jump of the frame in the web page! Navigate is still used, but requires two parameters! webbrowse.navigae('The web address to be transferred',flag1,flag2); The two parameters have the type: olevariant; The first parameter does not require assignment, it controls other options for opening the web page (such as: opening in a new web page, etc.). What we want to operate is the second parameter. Here you need to open the source file of the web page and check the name attribute of its frame! Remember to assign its value to flag2 to the frame name you want to control! This is all Open a web page in a frame! In this way, adding a timer and some code can make a complete water filling machine! |