UIBOT相對路徑定位,使元素更穩定2列表數據抓取(個人研究官網無教程)


圖1

 圖2

 

 

 如上圖1、2是同一個頁面的兩次操作,其中class的值第一次是col_3,第二次是col_103是是隨機生成的,如果用自帶的數據抓取,默認就是寫死的,多次打開此頁面,就會有操作失敗的情況。所以需要元素相對路徑的處理。

自動生成的代碼:

arrayData = UiElement.DataScrap({"html":[{"id":"app","tag":"DIV"}],"wnd":[{"app":"chrome","cls":"Chrome_WidgetWin_1","title":"*"},{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},{"Columns":[{"props":["text"],"selecors":[{"className":"home box-y","index":0,"prefix":"","tag":"div","value":"div.home.box-y"},{"className":"box-c1 box-x","index":0,"prefix":">","tag":"div","value":"div.box-c1.box-x"},{"className":"main-container box-c1","index":0,"prefix":">","tag":"div","value":"div.main-container.box-c1"},{"className":"main box-c1 box-y","index":0,"prefix":">","tag":"div","value":"div.main.box-c1.box-y"},{"className":"scroll-main box-c1","index":0,"prefix":">","tag":"div","value":"div.scroll-main.box-c1"},{"className":"content contentForList","index":0,"prefix":">","tag":"div","value":"div.content.contentForList"},{"className":"list-page-main parameter","index":0,"prefix":">","tag":"div","value":"div.list-page-main.parameter"},{"className":"box-c1 oh cc-table__empty-bgimg compact-table","index":0,"prefix":">","tag":"div","value":"div.box-c1.oh.cc-table__empty-bgimg.compact-table"},{"className":"vxe-table tid_105 border--full show--head has--height fixed--left fixed--right t--animat t--stripe row--highlight scroll--x","index":0,"prefix":">","tag":"div","value":"div.vxe-table.tid_105.border--full.show--head.has--height.fixed--left.fixed--right.t--animat.t--stripe.row--highlight.scroll--x"},{"className":"vxe-table--fixed-left-wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--fixed-left-wrapper"},{"className":"vxe-table--body-wrapper fixed-left--wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--body-wrapper.fixed-left--wrapper"},{"className":"vxe-table--body","index":0,"prefix":">","tag":"table","value":"table.vxe-table--body"},{"className":"","index":0,"prefix":">","tag":"tbody","value":"tbody"},{"index":0,"prefix":">","tag":"tr","value":"tr"},{"className":"vxe-body--column col_108 col--left col--ellipsis","index":0,"prefix":">","tag":"td","value":"td.vxe-body--column.col_108.col--left.col--ellipsis"},{"className":"vxe-cell c--tooltip","index":0,"prefix":">","tag":"div","value":"div.vxe-cell.c--tooltip"},{"className":"vxe-cell--label","index":0,"prefix":">","tag":"span","value":"span.vxe-cell--label"}]}],"ExtractTable":0},{"objNextLinkElement":"","iMaxNumberOfPage":5,"iMaxNumberOfResult":-1,"iDelayBetweenMS":1000,"bContinueOnError":false})

為了方便我轉成多行

arrayData = UiElement.DataScrap({"html":[{"id":"app","tag":"DIV"}],"wnd":[{"app":"chrome","cls":"Chrome_WidgetWin_1","title":"*"},
{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},
{"Columns":[{"props":["text"],"selecors":[{"className":"home box-y","index":0,"prefix":"","tag":"div","value":"div.home.box-y"},
{"className":"box-c1 box-x","index":0,"prefix":">","tag":"div","value":"div.box-c1.box-x"},
{"className":"main-container box-c1","index":0,"prefix":">","tag":"div","value":"div.main-container.box-c1"},
{"className":"main box-c1 box-y","index":0,"prefix":">","tag":"div","value":"div.main.box-c1.box-y"},
{"className":"scroll-main box-c1","index":0,"prefix":">","tag":"div","value":"div.scroll-main.box-c1"},
{"className":"content contentForList","index":0,"prefix":">","tag":"div","value":"div.content.contentForList"},
{"className":"list-page-main parameter","index":0,"prefix":">","tag":"div","value":"div.list-page-main.parameter"},
{"className":"box-c1 oh cc-table__empty-bgimg compact-table","index":0,"prefix":">","tag":"div","value":"div.box-c1.oh.cc-table__empty-bgimg.compact-table"},
{"className":"vxe-table tid_105 border--full show--head has--height fixed--left fixed--right t--animat t--stripe row--highlight scroll--x","index":0,"prefix":">","tag":"div","value":"div.vxe-table.tid_105.border--full.show--head.has--height.fixed--left.fixed--right.t--animat.t--stripe.row--highlight.scroll--x"},
{"className":"vxe-table--fixed-left-wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--fixed-left-wrapper"},
{"className":"vxe-table--body-wrapper fixed-left--wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--body-wrapper.fixed-left--wrapper"},
{"className":"vxe-table--body","index":0,"prefix":">","tag":"table","value":"table.vxe-table--body"},
{"className":"","index":0,"prefix":">","tag":"tbody","value":"tbody"},
{"index":0,"prefix":">","tag":"tr","value":"tr"},
{"className":"vxe-body--column col_108 col--left col--ellipsis","index":0,"prefix":">","tag":"td","value":"td.vxe-body--column.col_108.col--left.col--ellipsis"},
{"className":"vxe-cell c--tooltip","index":0,"prefix":">","tag":"div","value":"div.vxe-cell.c--tooltip"},
{"className":"vxe-cell--label","index":0,"prefix":">","tag":"span","value":"span.vxe-cell--label"}]}],"ExtractTable":0},
{"objNextLinkElement":"","iMaxNumberOfPage":5,"iMaxNumberOfResult":-1,"iDelayBetweenMS":1000,"bContinueOnError":false})

 

 手動處理后:

arrayData = UiElement.DataScrap({"html":[{"id":"app","tag":"DIV"}],"wnd":[{"app":"chrome","cls":"Chrome_WidgetWin_1","title":"*"},
{"cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},
{"Columns":[{"props":["text"],"selecors":[{"className":"home box-y","index":0,"prefix":"","tag":"div","value":"div.home.box-y"},
{"className":"box-c1 box-x","index":0,"prefix":">","tag":"div","value":"div.box-c1.box-x"},
{"className":"main-container box-c1","index":0,"prefix":">","tag":"div","value":"div.main-container.box-c1"},
{"className":"main box-c1 box-y","index":0,"prefix":">","tag":"div","value":"div.main.box-c1.box-y"},
{"className":"scroll-main box-c1","index":0,"prefix":">","tag":"div","value":"div.scroll-main.box-c1"},
{"className":"content contentForList","index":0,"prefix":">","tag":"div","value":"div.content.contentForList"},
{"className":"list-page-main parameter","index":0,"prefix":">","tag":"div","value":"div.list-page-main.parameter"},
{"className":"box-c1 oh cc-table__empty-bgimg compact-table","index":0,"prefix":">","tag":"div","value":"div.box-c1.oh.cc-table__empty-bgimg.compact-table"},
{"className":"vxe-table tid_105 border--full show--head has--height fixed--left fixed--right t--animat t--stripe row--highlight scroll--x","index":0,"prefix":">","tag":"div","value":"div.vxe-table.tid_105.border--full.show--head.has--height.fixed--left.fixed--right.t--animat.t--stripe.row--highlight.scroll--x"},
{"className":"vxe-table--fixed-left-wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--fixed-left-wrapper"},
{"className":"vxe-table--body-wrapper fixed-left--wrapper","index":0,"prefix":">","tag":"div","value":"div.vxe-table--body-wrapper.fixed-left--wrapper"},
{"className":"vxe-table--body","index":0,"prefix":">","tag":"table","value":"table.vxe-table--body"},
{"className":"","index":0,"prefix":">","tag":"tbody","value":"tbody"},
{"index":0,"prefix":">","tag":"tr","value":"tr"},
{"className":"vxe-body--column col--left col--ellipsis","index":3,"prefix":">","tag":"td","value":"td.vxe-body--column.col--left.col--ellipsis"},
{"className":"vxe-cell c--tooltip","index":0,"prefix":">","tag":"div","value":"div.vxe-cell.c--tooltip"},
{"className":"vxe-cell--label","index":0,"prefix":">","tag":"span","value":"span.vxe-cell--label"}]}],"ExtractTable":0},
{"objNextLinkElement":"","iMaxNumberOfPage":5,"iMaxNumberOfResult":-1,"iDelayBetweenMS":1000,"bContinueOnError":false})

刪除了col_108這個屬性值,並將index改為具體的第幾列。還可以直接寫成  {"index": 替換數字,"tag":"td","value":""}

如果上面的部分屬性也有這個數字動態變化的可以嘗試刪除,這個列表也是一級一級定位的,里面好多中間元素可以省去,因是自動錄制的缺點就是冗余,但是省力,小白也可以操作。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM