Функции, которые должны быть реализованы, показаны на следующей картине. Конкретные детали следующие:
Теперь я представлю некоторые другие функции программного обеспечения. Я надеюсь, что все выиграют.
Продукты поиска симулятора
При чистке заказов вы не можете напрямую получить URL -адрес продукта и ввести страницу покупки. Вы должны имитировать искусственный поиск.
В этом процессе есть две трудности:
1) асинхронная загрузка списка продуктов; 2) повернуть страницы и сделать скриншоты;
В саду я больше не играю с большим мечом перед Гуанским гонгом.
Прямая загрузка кода ключа:
I: Ищите продукты и поворачивайте страницы
Общественная лопатка? SearchProduct (taskDetailModel TaskDetailData) {bool? result = null; bool isindex = true; bool islist = true; webbrowsertask.instance.setProperties (); webbrowsertask.instance.cleardocumentCompleted (); webbrowsertask.instance.documentCompleted += (Wbsendersearch, wbesearch) => a aboumentseShereSearh System.windows.forms.webbrowser; System.windows.forms.htmldocument currentdoc = currentwb.document; mshtml.htmldocument currentdom = currentdoc.domdocument as mshtml.htmldocument; string wburl = wbesearch.url.tostring (); if (currentwb.readtate == straleat System.Windows.Forms.WebBrowserReadyState.Complete){#region Home Search if (wbUrl.Contains("www.taobao.com")){if (isIndex == true){isIndex = false;taskDetailData.DetailRemark = String.Format(@"Enter keywords""{0}""Search for product...", taskDetailData.taskName); func <bool> func = () => {bool asynctag = false; System.Threading.Thread.sleep (5000); Asynctag = true; return asynctag;}; func.begininvoke ((ar) => {bool asyncult = func.Endvoke (ar); (Asyncresult) {System.windows.forms.htmlelement heee = currentDoc.getElementById ("j_searchtab"); String classname = hee.getattribute ("classname"); System.windows.forms.htmlelement hitem = heee.children [0]; 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.fforms.htmlelement li -in in in heclis) li.getAttribute ("classname"); if (liclass.contains ("selected")) {System.windows.forms.htmlelement q = currentDoc.getElementById ("q"); System.windows.forms.htmlelement btnsearch = currentDoc.getElementByid ("j_tsearchform"). null && btnsearch! = null) {q.focus (); q.setattribute ("value", taskdetailData.taskname); btnsearch.focus (); string savepath = path.combine (userdata.workbenchdirectory, taskdetaildata.taskdetailailailailailailailailailailailailailailailailailailaillailailailailailailailailailailailailailailailailailailailailailailailailaile ")); CaptuctionImage.captureWebPageArea (currentdom, savePath); btnsearch.invokemempement (" click ");}}}}}}, null);}}#endregion home search#resigne product if (wburl.contains (" s.taobao. false; func <bool> func = () => {bool asynctag = false; asynctag = true; return asynctag;}; func.begininvoke ((ar) => {bool asyncresult = func.endinvoke (ar); if (asyncresult) {// анализировать продукт на странице ClickProductRuctRuctRuctRuctRuctRempore (asyncresult) {// анализировать продукт на странице ClickProductRuctRuctRuctRe и upersApe (asyncresult) {// Analyze Product Page PageProductR taskDetailData); result = true;}}, null);}}#Список продуктов Endregion}}; // DocumentCompleted End System.Windows.Application.current.dispatcher.invoke (new System.Action (() => {webBrowSertask.instance.navigate ("https://www.taobao.com/");}); для (int i = 0; i <120; i ++) {System.th.th.th.th.th.th.th (Результат! = null) {break;}} return Result;} II: Поскольку каждая страница загружается ненормально, выберите подходящее время, чтобы сделать скриншот веб -страницы и запечатлеть всю веб -страницу:
/*Because the control is included, if it is called in the thread, the Invoke method must be used with System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() =>{//htmlDoc.Window.ScrollTo(new System.Drawing.Point(5000, htmlDoc.Body.ScrollRectangle.Height));string savePath = string.format (@"d:/{0} .jpg", guid.newguid (). toString ()); captureImage.captureWebPage (webbrowSertask, savePath);}), System.Windows.thread </summary> //// <param name = "web"> </param> //// <param name = "savePath"> </param> public static void captureWebPage (System.Windows.forms.webbrowSer Web, String SavePath) {rectangle body = web.document.scrollRecter; rectAngle ocrect = new rectangle () {location = new.shopavel = newrage = newrage = incemangle = newrage = {) {). Новый размер (body.width, body.height)}; web.dock = dockstyle.none; web.width = docRectangle.width; web.height = docRectangle.height; прямоугольник imgrectangle = docRectangle; Использование (Bitmap Bitmap = new Bitmap (imgrectangle.width, imgrectangle.height)) {iviewobject ivo = web.document.domdocument as iviewobject; с помощью (Graphics g = graphics.fromimage (bitmap)) {intptr hdc = g.gethdc (); Ivo.Draw (1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, inptr. Intptr.zero, intptr.zero, hdc, ref imgrectangle, ref docrectangle, intptr.zero, 0); g.releasehdc (hdc);} bitmap.save (savepath, system.drawing.imagemageformat.jpeg); Сделайте определенную область веб -страницы:
//// <summary> ////////Mepcept part на веб -странице /// </summary> /// <param name = "htmldom"> </param> /// <param name = "savePath"> </param> public static void captureWebPageArea (mshtml.htmldocument htmldom, string savePath) System.io.path.getDirectoryName (savePath); if (! System.io.directory.exists (savedir)) {System.io.directory.createdirectory (savedir);} прямоугольник docRectangle = new Rectangle () {location = new Point (0, 0), // size = new Size. htmldom.body.offsetheight) size = new Size ((int) System.windows.systemparameters.primaryScreenWidth, (int) System.Windows.SystemParameters.primaryScreenHeight)}; прямоугольный imgrectangle = docRectangle; Использование (Bitmap Bitmap = new Bitmap (imgrectangle.width, imgrectangle.height)) {iviewobject ivo = htmldom как iviewobject; с помощью (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 (savepath, system.drawing.imagemageformat.jpeg); В этом коде есть много интересных фрагментов. Друзья, которые заинтересованы, узнают.