Las funciones a implementar se muestran en la siguiente imagen. Los detalles específicos son los siguientes:
Ahora presentaré otras funciones del software. Espero que todos se beneficien.
Productos de búsqueda de simuladores
Al cepillarse los pedidos, no puede obtener directamente una URL de producto e ingresar la página de compra. Tienes que simular una búsqueda artificial.
Hay dos dificultades en este proceso:
1) carga asincrónica de la lista de productos; 2) Gire las páginas y tome capturas de pantalla;
En el jardín, ya no juego con una gran espada frente a Guan Gong.
Cargue directamente el código clave:
I: Busque productos y páginas de giro
¿Bool público? SearchProduct (taskDetailModel taskDetailData) {bool? resultado = null; bool isIndex = true; bool islist = true; webbrowserTask.instance.setProperties (); webbrowserTask.instance.cLearDocumentCompleted (); webbrowserTask.instance.DocumentComCompleted += (wbsendersearch, wbesearch) => {system.windows.forms.forms.forms.former.completed += (wbsendersearch, wbesearch) => {System.windows.forms.forms.forms.former.completed += (wbsendersearch, wbesearch) => {System.windows.forms.forms.forms.former.completed += (wbsendersearch, wbesearch) => {System.windows.forms.forms.forms.former. como system.windows.forms.webbrowser; system.windows.forms.htmlDocument currentDoc = currentwb.document; mshtml.htmlDocument currentDom = currentDoc.document as mshtml.htmlDocument; string wburl = wbesearch.url.tostring (); if (centreRWB.READIENTESTATATE; System.windows.forms.webbrowserreadystate.complete) {#región de búsqueda de inicio if (wburl.contains ("www.taobao.com")) {if (isIndex == true) {isIndex = false; taskdetailData.DetaRark = String.Format (@"Ingrese las palabras clave" "{0}" Search ",", ",", ",", "," "," Search "," ". taskDetailData.TaskName); func <Bool> func = () => {bool asynctag = false; system.threading.thread.sleep (5000); asynctag = true; return asyncTag;}; func.begininvoke ((ar) => {bool asyncrlesulta = func.endinvoke (ar); si); si); si); si); (asyncresult) {system.windows.forms.htmlelement heee = currentDoc.getElementById ("j_searchTab"); string classname = heee.getAttribute ("classname"); system.windows.forms.htmlelement hitem = heee.children [0]; system.windows.forms.htmlelementColection hitem = Heee 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.windows.Forms.htmlelement li in heclis) li.getAttribute ("classname"); if (liclass.contains ("seleccionado")) {system.windows.forms.htmlelement q = currentDoc.getElementBy ("q"); system.windows.forms.htmlelement btnSearch = currentDoc.getEmementByid ("j_earchform"). [niños [niños [0]; != null && btnsearch != null){q.Focus();q.SetAttribute("value", taskDetailData.TaskName);btnsearch.Focus();string savePath = Path.Combine(UserData.WorkBenchDirectory, taskDetailData.TaskDetailCode, String.Format("Search Submission.jpg", "")); CaptureImage.CaptureWebPagearea (CurrentDom, SavePath); btnsearch.invokemember ("haga clic");}}}}}}, null);}}#endregion Home Search#Lista de productos de la región if (wBurl.contain falso; func <Bool> func = () => {bool asynctag = false; asyncTag = true; return asyncTag;}; func.begininvoke ((ar) => {bool asyncresult = func.Endinvoke (ar); if (asyncresult) {// analizar la cadena de productos de producto PERGE PAGE HECHEPRODUCTURL = TurningEpage (TurnyDOC, if, TurnyDoc, if) {// taskDetailData); resultado = true;}}, nulo);}}#Lista de productos de Endregion}}; // documentCompleted end system.windows.application.current.dispatcher.invoke (new System.Action (() => {webbrowserTask.instance.navigate ("https://www.taebao.com/");}); (resultado! = nulo) {break;}} return resultado;} II: Debido a que cada página se carga anormalmente, elija el momento apropiado para tomar una captura de pantalla de la página web y capturar toda la página web:
/*Debido a que el control está incluido, si se llama en el subproceso, el método de Invoke debe usarse con System.windows.application.current.dispatcher.invoke (new System.action (() => {// htmldoc.window.scrollto (new System.drawing.Point (5000, htmldoc.body.scrollRectangle.height); string.format (@"d:/{0} .jpg", guía.newguid (). toString ()); captureImage.CaptureWebPage (webbrowserTask, savePath);}), system.windows.threading.dispatcherPriority.background);*//// <rummary> ///TATECTE CECEMENTO TODA CECEMENT </summary>//// <param name="web"></param>//// <param name="savePath"></param>public static void CaptureWebPage(System.Windows.Forms.WebBrowser web, String savePath){Rectangle body = web.Document.Body.ScrollRectangle;Rectangle docRectangle = new Rectangle(){Location = new Point(0, 0), size = new Size (Body.Width, Body.Height)}; Web.dock = DockStyle.None; Web.Width = Docrectangle.Width; Web.Height = Docrectangle.height; rectangle imgrectangle = Docrectangle; usando (bitmap bitmap = new bitmap (imgrectangle.width, imgrectangle.height)) {iviewObject IVO = web.document.domDocument como iviewObject; usando (gráfico g = gráfico.fromimage (bitmap)) {intptr hdc = g.gethdc (); ivo.draw (1, -1, intptr.Zero, Intptr.zero, intptr.zero, hdc, ref iMgrectangle, refocrectangle, intptr.zero, 0); g.releaseHdc (hdc);} bitmap.save (SavePath, System.Drawing.Imaging.ImageFormat.jpeg); bitmap.dispose ();}}} Retir una cierta área de la página web:
/// <summary> //// Intercept parte de la página web //// </summary> /// <param name = "htmldom"> </param> /// <param name = "SavePath"> </param> public static void capturewebPagearea (mshtml.htmlDocument htmldom, string savepath) {string saveDir = = = = System.io.path.getDirectoryName (SavePath); if (! System.io.directory.exists (saveDir)) {system.io.directory.ceateedirectory (saveDir);} rectangle doccrectangle = new rectangle () {ubicación = nuevo punto (0, 0), // size = new size (htmldom.Body.Body htmldom.body.offsetheight) size = new size ((int) system.windows.systemParameters.PrimaryScreenWidth, (int) System.windows.SystemParameters.PrimaryScreenheight)}; rectangle imgrectangle = doCrectangle; usando (bitmap bitmap = new bitmap (imgrectangle.width, imgrectangle.height)) {iviewObject IVO = htmldom como iviewObject; usando (gráfico g = gráfico.fromimage (bitmap)) {intptr hdc = g.gethdc (); ivO.draw (1, -1, intptr.zero, intptr. Intptr.zero, intptr.zero, hdc, ref iMgrectangle, refocrectangle, intptr.zero, 0); g.releaseHdc (hdc);} bitmap.save (SavePath, System.Drawing.Imaging.ImageFormat.jpeg); bitmap.dispose ();}}} Hay muchos fragmentos interesantes en este código. Los amigos interesados lo descubrirán.