Fungsi yang akan diterapkan ditampilkan pada gambar berikut. Detail spesifiknya adalah sebagai berikut:
Sekarang saya akan memperkenalkan beberapa fungsi lain dari perangkat lunak. Saya berharap semua orang akan mendapat manfaat.
Produk Pencarian Simulator
Saat menyikat pesanan, Anda tidak dapat secara langsung mendapatkan URL produk dan memasukkan halaman pembelian. Anda harus mensimulasikan pencarian buatan.
Ada dua kesulitan dalam proses ini:
1) Memuat Daftar Produk Asinkron; 2) putar halaman dan ambil tangkapan layar;
Di taman, saya tidak lagi bermain dengan pedang besar di depan Guan Gong.
Langsung Unggah Kode Kunci:
I: Cari produk dan putar halaman
Bool publik? Pencarian produk (TaskDetailModel TaskDetailData) {bool? Hasil = null; bool isIndex = true; bool islist = true; webbrowserksask.instance.setProperties (); webbrowsertask.instance.clearDocumentCompleted (); webbrowsask.instance.documentcompleted += (wbsendersearch, wbesearch) => {wbesearch) => {wbesearch) {wbesearch) = {wbesearch) => {wbesearch) = {wbesearch) = {wbesearch) => {wbesearch). sebagai System.Windows.Forms.WebBrowser; System.Windows.Forms.htmldocument CurrentDoc = Currentwb.document; mshtml.htmldocument currentdom = CurrentDoc.domDocument sebagai mshtml.htmldocument; string wburl = wbesearch.url.tostring); System.windows.Forms.webbrowserReadyState.Compete) {#Region Home Search if (wburl.contains ("www.taobao.com")) {if (isIndex == true) {isIndex = false; TaskDetailData.DetailRemark = string.format (@"@" enter; TaskDetailData.DetailRemark = string.format (@" TaskDetailData.TaskName); func <bool> func = () => {bool asynctag = false; System.threading.thread.sleep (5000); asynctag = true; return asynctag; func.begininvoke ((ar) => {bool asyncreR = func.begininvoke ((AR) => {bool asyncrancul = func. (asyncResult) {System.windows.Forms.htmlelement heee = currentDoc.getElementById ("j_searchtab"); string className = heee.getattribute ("className"); System.windows.Forms.htmlelement hitem = heeeeeeeeeeee.chrenrren. 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.form.form.forms li.getAttribute ("className"); if (liclass.contains ("dipilih")) {System.windows.Forms.htmLelement q = currentDoc.getElementById ("q"); System.windows.Forms.htmLelement btnsearch = currentdoc.getelementByid ("if-forms.htmLelement btnsearch = currentdoc.getelementByid (" if-form. ! = null && btnsearch! = null) {q.focus (); q.setAttribute ("value", TaskDetailData.taskName); btnsearch.focus (); string savePath = path.combine (UserData.WorkBenchEctore.focus (); stringdata.tasking, "TaskData. "")); Captureimage.capturewebpagearea (saat ini, savePath); btnsearch.invokeMember ("klik");}}}}}, null);}}#endregion home pencarian#region list 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){//Analyze the product per page String clickProductURL = TurningAndParsePage(currentDoc, TaskDetailData); result = true;}}, null);}}#Daftar produk Endregion}}; // Document Completed End System.Windows.Application.current.dispatcher.invoke (System.action baru (() => {WebBrowserKask.instance.navigate ("https://www.taobao.com/");})); for (int i = 0; i <120; (hasil! = null) {break;}} hasil pengembalian;} II: Karena setiap halaman dimuat secara tidak normal, pilih waktu yang tepat untuk mengambil tangkapan layar halaman web dan menangkap seluruh halaman web:
/*Karena kontrol disertakan, jika dipanggil dalam utas, metode Invoke harus digunakan dengan System.Windows.Application.current.dispatcher.invoke (System.action baru (() => {// htmldoc.window.scrollto (new System.drawing.point (5000, htmldoc.scrollto (new System.drawing.point (5000, htmldoc.scrollto (new System.drawing.point (5000, htmldoc.boPcrollto (new System.drawing.point (5000, htmldoc.boPcrollto (new System.drawing.point (5000, htmldoc.boLody. 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"></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 = ukuran baru (body.width, body.height)}; web.dock = dockstyle.none; web.width = docrectangle.width; web.height = dOcrectangle.height; rectangle iMgrectangle = dOcrectangle; Menggunakan (bitmap bitmap = bitmap baru (iMgrectangle.width, iMgrectangle.height)) {iviewObject ivo = web.document.domDocument sebagai iviewObject; menggunakan (grafik g = grafik. Intptr.zero, intptr.zero, hdc, ref Imgrectangle, refrectangle, intptr.zero, 0); g.releasehdc (hdc);} bitmap.save (savePath, system.drawing.imaging.imageformat.jpeg); bitmap.dispose ();; imaging.imageformat.jpeg); bitmap.dispose ();; Imageformat.jpeg); bitmap.dispose ();;); bitmap.dispose ();;); bitmap.dispose ();;); bitmap. Snap area tertentu dari halaman web:
/// <summary> //// intercept bagian dari halaman web /// </summary> /// <param name = "htmldom"> </param> /// <param name = "savePath"> </param> public void captureWebPagearea (mshtml.htmldocument htmoid htmomomomomomomomomun 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). htmldom.body.offsetHeight) size = ukuran baru ((int) system.windows.systemparameters.primaryscreenwidth, (int) system.windows.systemparameters.primaryscreenheight)}; rectangle iMgrectangle = Docrectangle; menggunakan (bitmap bitmap = bitmap baru (imgrectangle.width, imgrectangle.height)) {iviewObject ivo = htmldom sebagai iviewObject; menggunakan (grafik g = grafik. Intptr.zero, intptr.zero, hdc, ref Imgrectangle, refrectangle, intptr.zero, 0); g.releasehdc (hdc);} bitmap.save (savePath, system.drawing.imaging.imageformat.jpeg); bitmap.dispose ();; imaging.imageformat.jpeg); bitmap.dispose ();; Imageformat.jpeg); bitmap.dispose ();;); bitmap.dispose ();;); bitmap.dispose ();;); bitmap. Ada banyak cuplikan menarik dalam kode ini. Teman yang tertarik akan mencari tahu.