Jump to content

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
Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...