uibot数据抓取+数据表+excel小案例

uibot数据抓取+数据表+excel小案例

Dim arrayData = ""
Dim objDatatable = ""
Dim objExcelWorkBook = ""
Dim arrayRet = ""
Dim iRet = ""
Dim objRet = ""
Dim sRet = ""
Dim arrayText = ""
// 网页数据抓取,返回值为二维数组
arrayData = UiElement.DataScrap({
     "html":{
     "attrMap":{
     "id":"content_left","tag":"DIV"},"index":0,"tagName":"DIV"},"wnd":[{
     "app":"uibotBrowser","cls":"Chrome_WidgetWin_*","title":"*"},{
     "cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},{
     "Columns":[{
     "props":["text","url"],"selecors":[{
     "index":0,"prefix":"","tag":"div","value":"div"},{
     "index":0,"prefix":">","tag":"h3","value":"h3"},{
     "className":"","index":0,"prefix":">","tag":"a","value":"a"}]}],"ExtractTable":0},{
     "objNextLinkElement":{
     "html":{
     "attrMap":{
     "aaname":"下一页 >","parentid":"page","tag":"A"},"index":0,"tagName":"A"},"wnd":[{
     "app":"uibotBrowser","cls":"Chrome_WidgetWin_*","title":"*"},{
     "cls":"Chrome_RenderWidgetHostHWND","title":"Chrome Legacy Window"}]},"iMaxNumberOfPage":1,"iMaxNumberOfResult":-1,"iDelayBetweenMS":1000,"bContinueOnError":False})
// 构建数据表,表头为内容和url
objDatatable = Datatable.BuildDataTable(arrayData,["内容","url"])
// 数据表根据条件查询
objDatatable = Datatable.QueryDataTable(objDatatable,"内容.str.contains(\"工具\")")
// 根据内容进行去重
objDatatable = Datatable.DropDuplicatesDataTable(objDatatable,[内容],"first")
// 将数据表转为二维数组
objDatatable = Datatable.GetDataTableByArray(objDatatable,False)
Try
    // 打开excel
    objExcelWorkBook = Excel.OpenExcel("f:\\Users\\Administrator\\Desktop\\123.xlsx",True,"Excel","","")
    // 循环遍历每一个单元格
    // 行从1开始,列从'A'开始
    For i = 1 To Excel.GetRowsCount(objExcelWorkBook,"Sheet1") Step 1 
        For j = Asc("A") To Excel.GetColumsCount(objExcelWorkBook,"Sheet1")+Asc("A")-1 Step 1 
            TracePrint(Excel.ReadCell(objExcelWorkBook,"Sheet1",Chr(j)&i))
        Next
    Next
    Excel.CloseExcel(objExcelWorkBook,True)
Catch
    Log.Error("操作excel出错")
Else

End Try

你可能感兴趣的:(uibot)