Les fonctions à implémenter sont affichées dans l'image suivante. Les détails spécifiques sont les suivants:
Maintenant, je vais présenter d'autres fonctions du logiciel. J'espère que tout le monde en bénéficiera.
Produits de recherche de simulation
Lors du brossage des commandes, vous ne pouvez pas obtenir directement une URL du produit et saisir la page d'achat. Vous devez simuler une recherche artificielle.
Il y a deux difficultés dans ce processus:
1) Chargement asynchrone de la liste des produits; 2) Tourner les pages et prendre des captures d'écran;
Dans le jardin, je ne joue plus avec une grande épée devant Guan Gong.
Téléchargez directement le code de clé:
I: Rechercher des produits et tourner les pages
Bool public? SearchProduct (taskDetailModel taskDetailData) {bool? result = null; bool isIndex = true; bool isList = true; webbrowsertask.instance.setProperties (); webbrowsertask.instance.cleDocumentCompleted (); webBrowsertask.instance.DocumentCompleted + = (wbsendersearch System.Windows.Forms.WebBrowser; System.Windows.Forms.HtMLDocument CurrentDoc = CurrentWB.Document; Mshtml.HtMLDocument; String Wurl = WBeSearch.Tostring (); System.Windows.Forms.WebBrowSerreadyState. taskDetailData.TaskName); func <bool> func = () => {bool asynctag = false; system.threading.thread.sleep (5000); asynctag = true; return asynctag;}; func.beginInke (ar) => {bool asyncrensult = func.endinvoke (ar); if (asyncresult) {System.Windows.Forms.htmlelement heee = currentdoc.getElementById ("j_searchtab"); string classname = heee.getAttribute ("className"); system.windows.forms.htmlelement hittem = heee.children [0]; System.windows.forms.forms.htmlelementCollection HECLISE = System.Windows.Forms.htmlelementCollection HECLISE = System.Windows.Forms.htmlelementCollect hitem.children; system.windows.forms.htmlelement li1 = heclis [0]; system.windows.forms.htmlelement li2 = heclis [1]; System.Windows.Forms.htmlelement li3 = heclis [2]; ForEach (System. li.getAttribute ("classname"); if (liclass.contains ("sélectionné")) {System.Windows.Forms.htmlelement Q = CurrentDoc.getElementById ("Q"); System.Windows.Forms.htmlelement btnsearch = CurrentDoc.getElementyid ("j_Tearchform"). null && btnsearch! = null) {q.focus (); q.setAttribute ("valeur", taskDetailData.taskName); btnsearch.focus (); string Savepath = path.combine (userdata.workbenchDirectory, taskdetaildata.taskdetailcode "")); CaptureImage.CaptureWebPageArea (Currentdom, SavePath); btnSearch.invokeMember ("Click");}}}}}}, null);}} # Endregion Home Search # Region Liste de la région if (Wurl.ConTains ("S.Taobao.com")) {If (isList ==) false; func <bool> func = () => {bool asynctag = false; asynctag = true; return asynctag;}; func.begininvoke ((ar) => {bool asyncresult = func.endinvoke (ar); if (asyncresult) {// analyser le producteur par chaîne ClickProductrl = TurningAndaRsepage (Curve taskDetailData); result = true;}}, null);}} # list de produits EndRegion}}; // DocumentCompleted End System.Windows.Application.Current.Dispatcher.invoke (new System.Action (() => {webbrowsertask.instance.navigate ("https://www.taobao.com/");})); pour (int i = 0; i <120; i ++) {System.threading. (résultat! = null) {break;}} Retour Résultat;} II: Étant donné que chaque page est chargée anormalement, choisissez le temps approprié pour prendre une capture d'écran de la page Web et capturer la page Web entière:
/ * Parce que le contrôle est inclus, s'il est appelé dans le thread, la méthode invoquée doit être utilisée avec System.Windows.Application.current.Dispatcher.invoke (new System.Action (() => {// htmldoc.window.scrollto (new System.Drawing.Point (5000, htmldodody.scrolltor string.Format(@"D:/{0}.jpg", Guid.NewGuid().ToString());CaptureImage.CaptureWebPage(webBrowserTask, savePath);}), System.Windows.Threading.DispatcherPriority.Background);*//// <summary>//// Intercept the entire web page//// </summary> //// <param name = "web"> </ param> //// <param name = "SavePath"> </amor> public static void capturewebpage (System.Windows.Forms.webBrowser, String SavePath) {rectangle body = web.Document.body.scrollrectang 0), size = new size (body.width, body.height)}; web.dock = dockstyle.none; web.width = docrectangle.width; web.height = doCrectangle.Height; rectangle imgrectangle = doCrectangle; Utilisation (bitmap bitmap = new Bitmap (imGrectangle.width, imgrectangle.height)) {iViewObject iVo = web.Document.DoDocument as iViewObject; Using (Graphics G = Graphics.Fromimage (bitmap)) {intptr hdc = g.gethdc (); evo.draw (1, -1, int.zo Intptr.zero, intptr.zero, hdc, ref iMgrectangle, ref doCrectangle, intptr.zero, 0); g.releasehdc (hdc);} bitmap.save (bitmap.dispose ();}} Cassez une certaine zone de la page Web:
/// <summary> //// Intercepter la partie de la page Web /// </summary> /// <param name = "htmldom"> </ param> /// <param name = "SavePath"> </ param> public void capturewebpagearea (mshtml.htmldocument htmldom, string SavePath) {string savedir = System.io.path.getDirectoryName (SavePath); if (! System.io.directory.exists (SaveDir)) {System.io.Directory.CreateDirectory (Savedir);} rectangle doCrectangle = new rectangle () {location = new Point (0, 0), // size = new size (htmldom.body.body. htmldom.body.offsetheight) size = new size ((int) System.Windows.SystemParameters.primaryscreenwidth, (int) System.Windows.SystemParameters.primaryScreenHeight)}; recangle IMGrectangle = DoCrectangle; Utilisation (bitmap bitmap = new bitmap (imgrectangle.width, imgrectangle.height)) {iViewObject iVo = htmldom as iViewObject; Using (graphics g = graphics.fromimage (bitmap)) {intptr hdc = g.Gethdc (); Intptr.zero, intptr.zero, hdc, ref iMgrectangle, ref doCrectangle, intptr.zero, 0); g.releasehdc (hdc);} bitmap.save (bitmap.dispose ();}} Il y a beaucoup d'extraits intéressants dans ce code. Les amis intéressés le découvriront.