Jump to content
JackER4565

Getting info from a website with arrays and table read (Optimize my code)

Recommended Posts

Hi, first of all thanks to all the guys who always help people in the forums, I wouldn't be able to do anything if wasn't for your help, even if I don't ask it myself.

 

I've created this code to get some info on a monitoring network on my work. It relays on _IETableGetCollection and _IETableWriteToArray.

It works well, but take around 3:25 minutes to get the info from 28 pages (some of them are large and take longer to load, but most of them are small and fast).

My question is if you see a way to get the program to go faster...

 

I've tried to make it easy for you to understand and edited somethings with sensitive info.

(Some of the pages doesn't have the black divider with MIRA in the end, so I need to search if it is there or not.)

 

#include <IE.au3>
#include <array.au3>

Local $oIE = _IECreate("about:blank", 0, 0)
Local $paginas[28] = [89, 90, 91, 92, 93, 96, 105, 113, 119, 125, 126, 129, 131, 133, 135, 137, 139, 140, 141, 144, 145, 146, 148, 149, 150, 151, 158, 159]
Local $Datos_array[0][2]
Local $oTable
Local $tabla
Local $aux_x = 1
Local $ar = 1
Local $Numtables_datos = 0
MsgBox(0, "asd", "asd")
For $pag = 0 To UBound($paginas) - 1 Step 1
    _IENavigate($oIE, "<WEBSITE URL>" & $paginas[$pag]) ; <<< the pages to load are always the same except for the last digits.


    _ArrayAdd($Datos_array, $paginas[$pag] & "|" & "Entrante", 0, "|") ; <<<<<<<<<<<<<<<< adds the page number toarray  [0, 0] 

    ;############################################ START counts amount of tables with traffic
    $oTable = _IETableGetCollection($oIE)
    Local $iNumTables = @extended
    For $i = 3 To $iNumTables - 2 Step 1
        $oTable = _IETableGetCollection($oIE, $i)
        $nomb_tabla2 = _IETableWriteToArray($oTable) ; <<<<<<<< TABLE TO ARRAY.
        $string2 = StringStripWS($nomb_tabla2[1][0], 8)
        If $string2 <> "MIRA" Then $Numtables_datos = $Numtables_datos + 1
    Next
    $tabla_End = $iNumTables - $Numtables_datos
    ;############################################ FIN

    $tabla_Start = 4
    $tabla_trafico = 2
    For $for = 1 To $Numtables_datos Step 1

        $oTable = _IETableGetCollection($oIE, $tabla_Start - 1) ; <<<<<<<<<<< NAME OF THE TABLE; row2 = mira

        $nomb_tabla = _IETableWriteToArray($oTable) ; <<<<<<<< TABLE TO ARRAY

        ;########################################### ADDS the traffic number into the row
        $string = StringStripWS($nomb_tabla[1][0], 8)
        If $string == "MIRA" Then
            ;si o si pasa por aca 1 vez
            _ArrayAdd($Datos_array, $nomb_tabla[0][0])
            $nomb_aux = $nomb_tabla[0][0]
            $aux_x = 1
            $tabla_trafico = $tabla_trafico + 2
        Else
            ;esto deberia ser por row
            _ArrayAdd($Datos_array, $nomb_aux & " " & $aux_x)
            $aux_x = $aux_x + 1
            $tabla_trafico = $tabla_trafico + 1
        EndIf

        $oTable = _IETableGetCollection($oIE, $tabla_trafico)
        Local $aTableData = _IETableWriteToArray($oTable)

        $bps = _ArrayToString($aTableData, "|", 0, 0, @CRLF, 0, 0)
        $bps = StringRight($bps, 5)
        $bps = StringLeft($bps, 4)
        $trafico_actual = _ArrayToString($aTableData, "|", 0, 0, @CRLF, 2, 2)
        If $bps == "Gbps" Then $trafico_actual = $trafico_actual * 1000
        If $bps == "Kbps" Then $trafico_actual = $trafico_actual / 1000
        $Datos_array[$ar][1] = $trafico_actual
        $ar = $ar + 1

        If $string == "MIRA" Then

            $tabla_Start = $tabla_Start + 2
        Else
            $tabla_Start = $tabla_Start + 1
        EndIf
    Next
    $ar = $ar + 1




;~ ############# CAÍDA ############
;~          If $actual_entrante = 0 Then
;~              $xxx = 0
;~              Do

;~              MsgBox(0, "Tráfico Caído", $paginas[$i], 5)
;~                  $xxx = $xxx + 1
;~              Until $xxx = 10
;~          EndIf
;~ ############# CAÍDA ############.
    Local $Numtables_datos = 0
Next
_ArrayDisplay($Datos_array, "Array display")
_IEQuit($oIE)

Thanks!! 

array output.png

WEB SCREENSHOT2.png

monitoria.html

Edited by JackER4565

Share this post


Link to post
Share on other sites
16 hours ago, Danp2 said:

You could likely shave off some time by loading some of the slower pages in a background tab and then using _IEAttach to select them as needed.

good idea, will try it and share the results!

 

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Zaoka
      Hi guys
      Need little help with filtering.
      I'm trying to filter specific weeks from power pivot table using this code recorded with Excel VBA :
       
      #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\....\Orders.xlsb") $oWorkbook.PivotTables("PivotTable1").PivotFields( _ "[Report 2].[Week].[Week]").VisibleItemsList = Array( _ "[Report 2].[Week].&[10]", "[Report 2].[Week].&[11]", _ "[Report 2].[Week].&[12]", "[Report 2].[Week].&[13]", _ "[Report 2].[Week].&[14]", "[Report 2].[Week].&[15]") But get error
      error: Array(): undefined function. Not sure how to resolve this.
    • By LxP
      I'm trying to pass a nested array to a function, such that the function alters the inner array.
      I was surprised to find that this minimal reproducible example, despite its use of ByRef, seems to pass a copy of the inner array to the function:
      #include <Array.au3> ; a boring old array Local $aInnerArray[5] = [1, 2, 3, 4, 5] ; a one-element array containing a reference to the other array Local $aOuterArray[1] = [$aInnerArray] ; intention: take a nested array and alter its inner array ; reality: the inner array seems to be getting copied Func ChangeIt(ByRef $aOuter) Local $aInner = $aOuter[0] $aInner[2] = 0 EndFunc ; Expected: [1, 2, 3, 4, 5] ; Actual: [1, 2, 3, 4, 5] ✔ _ArrayDisplay($aInnerArray, 'Before') ; $aOuterArray passed by-ref, should receive reference to $aInnerArray ; Therefore should change $aInnerArray to [1, 2, 0, 4, 5] ChangeIt($aOuterArray) ; Expected: [1, 2, 0, 4, 5] ; Actual: [1, 2, 3, 4, 5] ✘ _ArrayDisplay($aInnerArray, 'After') I suspect that either:
      the copy is taking place in the first line of the function (I couldn't find a way to access the inner array without first assigning it to a variable though); or ByRef doesn't propagate into inner levels of the data structure being passed, which seems less likely to me. Could someone please point me in the right direction to get this working as intended?
      Update: the answer
      ; WRONG: ; a one-element array containing a reference to the other array Local $aOuterArray[1] = [$aInnerArray] The assumption I made about this code is wrong—it actually copies $aInnerArray into $aOuterArray, so there are now two unrelated $aInnerArray instances.  It is not possible to store arrays in other arrays by reference.
      If it is necessary to refer to a mutable array in multiple places, consider holding it in a global variable.  Where a collection of mutable arrays needs to be accessed in multiple places (as in my case), consider storing them in a global array and referring to each sub-array by index (also known as the Registry pattern).
    • By VinMe
      HELLO All,
      is there any function in Auto it to Remove the repeating  strings separated by ","  which is present in the array.
      ex.
      Available state
      a[0]= D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D85,D86,D85,D86
      a[1]=D85,D24,,,,,D85
      Required state
      a[0]= D97,D96,D85,D86,
      a[1]=D85,D24
      thank  you in advance!
      vin!
    • By ahha
      Okay I know this will be one of those - how stupid can I be when I see the answer but I'm baffled at the current time.
      #include <Debug.au3> Local $aArray[11][2] = [ [10,10],[1,5],[2,0],[3,0],[4,"M"],[5,0],[6,0],[7,0],[8,"M"],[9,0],[10,2] ] _DebugArrayDisplay($aArray, "$aArray") Local $iCount = 0 ;init Local $i For $i = 1 to $aArray[0][0] If $aArray[$i][1] = "M" Then $iCount = $iCount + 1 ;debug ;MsgBox($MB_OK + $MB_TOPMOST, "Debug", "$aArray[$i][0] = " & $aArray[$i][0] & @CRLF & "$aArray[$i][1] = " & $aArray[$i][1]) EndIf Next MsgBox($MB_OK + $MB_TOPMOST, "Info", "M's found = " & $iCount) When I run this it states there are 8 M's in the array.
    • By D2thunder
      Hi all, I wasnt active in this Forum forum for Years. 😅
      Since I need something with Json in AutoIt i write a little UDF to save a variable to file to read it with another language - and back. After a while until my other script grows i thought - lets integrate all variables wich is possible, because i want have arrays to.
      This is my first public UDF in Autoit - normaly my AutoIt scripts are quick an dirty.... - like the examples for this udf. - someone want to write nice examples?
      I tried to write this UDF properly, cared for processing speed, low mem consumption as possible, a short code, and a high usability without beeing very familiar with arrays.
      What is it for? - convert nearly all types of variables to a json string for saving it in a file or to an ini. Read it back in to a same formated variable and preserv variable types. All array types are supported with nested arrays, the only restriction is ram and array/stringsize - and time if the array is very big. You can use Filters for variable types and some other options.
      If anyone found a bug or any suggestions, please post it.
       
      get Json.au3 from here Json.au3
       
       
      JsonVar 2019.01.25.1.zip
×
×
  • Create New...