実装する機能は、次の写真に示されています。具体的な詳細は次のとおりです。
次に、ソフトウェアの他の機能を紹介します。みんなが恩恵を受けることを願っています。
シミュレーター検索製品
注文をブラッシングするとき、製品URLを直接取得して購入ページを入力することはできません。人工検索をシミュレートする必要があります。
このプロセスには2つの困難があります。
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 => System.windows.forms.webbrowser; system.windows.htmldocument currentdoc = currentwb.document; mshtml.htmldocument currentdoc.domdocument as mshtml.htmldocument; string wburl = wburl = wbesearch.url.tostring System.Windows.forms.webbrowsertate.complete){#リージョンホーム検索if(wburl.contains( "www.taobao.com"))){if(isindex = false; tashdetaildata.detailremark = string.format(@"" {0 " taskdetaildata.taskname); func <bool> func =()=> {bool asynctag = false; system.threading.thread.sleep(5000); asynctag = true; return asynctag;}; func.begininvoke((ar)=> {bool asyncrult = func.endinvoke(a ar); (asyncresult){system.windows.forms.htmlelement heee = currentdoc.getelementbyid( "j_searchtab"); string classname = heee.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]; li.getAttribute( "className"); if(liclass.contains( "selected")){system.windows.forms.htmlelement q = currentdoc.getelementbyid( "q"); windows.forms.htmlelement btnsearch = currentdoc.getelementyid(ef [0]; " != null && btnsearch!= null){q.focus(); q.setattribute( "value"、taskdetaildata.taskname); btnsearch.focus(); string savepath = path.combine(userdata.workbenchdirectory、taskdetaildata.taskdetailcod、 " ")); Capture.capturewebpagearea(currentdom、savepath); btnsearch.invokemember(" click ");}}}}}}}}}}#enendregion home home search#region product list if(wburl.contains(" s.taobao.com "){is(islist = troom) false; func <bool> func =()=> {bool asynctag = false; asynctag = true; return asynctag;}; func.beginInvoke((ar)=> {bool asyncresult = func.endinvoke( taskdetaildata); result = true;}}、null);}}#endregion製品リスト}}}; // DocumentCompleted End System.Windows.Application.Current.dispatcher.invoke(new System.action(()=> {webbrowsertask.instance.navigate( "https://www.taobao.com/");})); for(int i = 0; i <120; i ++){system.threading.thread.sleep(1000); if(result!= null){break;}} return result;} II:各ページが異常にロードされているため、適切な時間を選択して、Webページのスクリーンショットを撮影し、Webページ全体をキャプチャします。
/*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()); capturemage.capturewebpage(webbrowsertask、savepath);})、system.windows.threding.dispatcherpriority.background); </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.scrollectangle;新しいサイズ(body.width、body.height)}; web.dock = dockstyle.none; web.width = docrectangle.width; web.height = docrectangle.height; rectangle imgrectangle = docrectangle; (bitmap bitmap = new bitmap(imgrectangle.width、imgrectangle.height)){iviewobject ivo = web.document.domdocument as iviewobject;を使用する(グラフィックg = graghtics.fromimage(bitmap)){intptr hdc = g.gethdc = g.gethdc intptr.zero、intptr.zero、hdc、ref imgrectangle、ref docrectangle、intptr.zero、0); g.releasehdc(hdc);} bitmap.save(savepath、system.drawing.imaging.imageformat.jpeg); bitmap.disose();}}}} Webページの特定の領域をスナップします。
/// <summary> /// Webページの一部をインターセプトする/// </summary> /// System.io.path.getDirectoryName(savepath); if(!system.io.directory.exists){system.io.directory.createdirectory(savedir);}長方形= new rectangle(){location = new point(0、0) htmldom.body.offsetheigh)size = new size((int)system.windows.systemparameters.primaryscreenwidth、(int)system.windows.systemsparameters.primaryscreenheight)}; rectangle imgrectangle = docrectangle; (bitmap bitmap = new bitmap(imgrectangle.width、imgrectangle.height)){iviewobject ivo = htmldom as iviewobject; fuly(graphics g = graphics.fromap(bitmap)){intptr hdc = g.gethdc(); ivo.draw(1の-1、ner intptr.zero、intptr.zero、intptr.zero、hdc、ref imgrectangle、ref docrectangle、intptr.zero、0); g.releasehdc(hdc);} bitmap.save(save.system.drawing.imaging.imageformat.jpeg); bitmap.dispose();このコードには多くの興味深いスニペットがあります。興味のある友達が知るでしょう。