After obtaining a page, webbrowser can execute script functions on the page. For example
Htmlelement. invokemember () method
Or
Htmldocument Doc = webbrowser1.document;
Doc. invokescript (jsfun, new object []... {jsparameter });
But does Java's httpclient seem to be okay?
The following is an article about using webbrowser to implement this task:
C #, webbrowser, login, data filling, analog click link, run JS function (http://www.outdosoft.com/winfrom/57372116J.html)
Determine whether the network is normal
Private bool isconnectedtointernet ()
{
Int DESC;
Return Internet. internetgetconnectedstate (Out DESC, 0 );
}
Set the default page:
Webbrowser1.navigate (New uri ("http://www.ic2ic.com/copy.jsp "));
Logon code:
Private void btnlogin_click (Object sender, eventargs E)
{
Webbrowser1.document. getelementbyid ("ID"). innertext = txtuser. Text. tostring (). Trim (); // fill name
Webbrowser1.document. getelementbyid ("passwd"). innertext = txtpwd. Text. tostring (). Trim (); // fill pwd
Htmlelement formlogin = webbrowser1.document. Forms ["frmlogin"];
Formlogin. invokemember ("Submit ");
Thread. Sleep (5000 );
Herfclick ("http://www.ic2ic.com/upload.jsp"); // This is a successful login operation, jump to // upload. asp
// Note that the link is not directly skipped.
// The session will not be lost.
Herfclick ("http://www.ic2ic.com/copy.jsp ");
}
Simulated click link:
Private void herfclick (string URL)
{
For (INT I = 0; I <webbrowser1.document. All. Count; I ++)
{
If (webbrowser1.document. all [I]. tagname = "A" & webbrowser1.document. all [I]. getattribute ("href "). tostring (). trim () = URL)
{
Webbrowser1.document. All [I]. invokemember ("click"); // triggers the "click" event.
Break;
}
}
}
Run JS functions on the webpage
Private void calljsmethod (string jsfun, string jsparameter) // function name, function parameter
{
Htmldocument Doc = webbrowser1.document;
Doc. invokescript (jsfun, new object []... {jsparameter });
}
Fill data:
Private void filldate (string txt)
{
Htmlelement frmword = webbrowser1.document. Forms ["frmword"]; // find from
Htmlelementcollection txtarea = frmword. getelementsbytagname ("textarea ");
Htmlelementcollection radio = frmword. getelementsbytagname ("input ");
Radio [2]. invokemember ("click"); // select the radio control
Txtarea [0]. innertext = TXT. tostring ();
}