图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":""}
如果上面的部分属性也有这个数字动态变化的可以尝试删除,这个列表也是一级一级定位的,里面好多中间元素可以省去,因是自动录制的缺点就是冗余,但是省力,小白也可以操作。