Jump to content

Loop required to repeat script for number of times


Imranimi
 Share

Recommended Posts

I have implemented all these loops (Do, For, while) but  unable to figure the right way. Thanks to AutoIT-Help Document & @Nine to support me in completing my script.

I am sharing the script:

<

$oIE1 = _IECreate("http://repl.flexlink.com/os/products.htm")
Sleep(3000)


Global $oInputs = _IETagNameGetCollection($oIE1, "a")

        For $oInput In $oInputs
            if $oInput.title = "More information" then
                Global $oIELink = $oInput

            ExitLoop
            endif
        Next

    MsgBox($MB_SYSTEMMODAL, "Product Name", $oIELink.href)

    Global $oIE2 = _IECreateTab ($oIE1, $oIELink.href)

    Func _IECreateTab (ByRef $oIE, $url)
        Local $Count = 0, $oIE2
        $oIE.Navigate ($url, $ie_newtab)
        $oIE2 = _IEAttach($url, "url")
        _IELoadWait ($oIE2, 300)
        return $oIE2
    EndFunc

MsgBox($MB_SYSTEMMODAL, "Accessories", "Switch to Next Product")

Sleep(3000)

Send("^w")

>

 

Link to comment
Share on other sites

@faustf Thanks, i will rectify my script with _IELoadWait

I actually need to open all the hypertext with title "More information" one by one in new tab. The above script is working fine with single move but i need to make it in loop & it should start with the next hypertext on completing the loop.

I am sharing the screenshot below, my above script is taking the detail of 1st hypertext "WKTL150" with title "More information" and opens in new-tab, my target is when i close the 1st hypertext-tab & come to this home-page it should open the 2nd-hypertext in new-tab & then close, then open & close 3rd, 4th & 5th one by one.

 

autoit-help1.png

Link to comment
Share on other sites

control if array  have only hypertext  that you interest   _arraydisplay($array)

if  yes  do a loop   classical  is  For $i=0 to ubound($array) -1

if  no  clean before array  or much better use  regexp  for take only a correct   link

but  with out  browse page is  difficult give  a suggest

 

Edited by faustf
Link to comment
Share on other sites

On 20/02/2019 at 5:48 PM, faustf said:

control if array  have only hypertext  that you interest   _arraydisplay($array)

if  yes  do a loop   classical  is  For $i=0 to ubound($array) -1

if  no  clean before array  or much better use  regexp  for take only a correct   link

but  with out  browse page is  difficult give  a suggest

 

@faustf, Bundle of thanks for pointing out this solution, can you make an example script of the above point. as i am checking in help i am unable to find the exact example on handling hypertexts in the array & making them in loop.

If you give me a way for handling more than 3 hypertext in array & open them in next tab one by one in sequence.

Link to comment
Share on other sites

this is a possible example what i spoken

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <InetConstants.au3>
#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <INet.au3>
;#include <Excel.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <Misc.au3>
#include <Debug.au3>


Local $path = "https://www.immobiliare.it/ricerca.php?idCategoria=1&idContratto=1&idTipologia=&sottotipologia=&idTipologiaStanza=&idFasciaPrezzo=&idNazione=IT&idRegione=&idProvincia=&idComune=&idLocalita=&idAreaGeografica=&prezzoMinimo=&prezzoMassimo=&balcone=&balconeOterrazzo=&boxOpostoauto=&stato=&terrazzo=&bagni=&mappa=&foto=&superficie=&superficieMinima=&superficieMassima=&raggio=&locali=&localiMinimo=&localiMassimo=&criterio=rilevanza&ordine=desc&map=0&tipoProprieta=&arredato=&inAsta=&noAste=&aReddito=&fumatore=&animali=&franchising=&flagNc=&gayfriendly=&internet=&sessoInquilini=&vacanze=&categoriaStanza=&fkTipologiaStanza=&ascensore=&classeEnergetica=&verticaleAste=&occupazioneInquilini=&pag=1&vrt=43.84357086564766,10.488960742950441;43.84241015467616,10.494132041931154;43.84333872526002,10.493659973144533;43.84487083512528,10.49524784088135;43.84627910342516,10.49275875091553;43.8465421828286,10.49123525619507;43.845830318235556,10.490291118621828;43.84578389198876,10.488703250885011"
$oIE = _IECreate($path, 0, 1, 1, 1) ; <--- 0011 invisible explorer  <--- 0111 visible explorer
_IELoadWait($oIE, 1, 1)
$sGHtmlPag = _IEBodyReadHTML($oIE)
Local $aLLinkInserz = StringRegExp($sGHtmlPag, '(?i)<a title=".+?" id=".+?" href="(.*?)"', 3)
_ArrayDisplay($aLLinkInserz)


for $i=0 To ubound ($aLLinkInserz) -1
; this is a simple for with array 
; here you can open in tab (but i dont like )---> url 1...... to  10 --> $aLLinkInserz[$i]
; or open in new window  
; and do much more ......
; enjoy.

Next

 

Link to comment
Share on other sites

@faustf, I need to stick to href.title (which is similar) in all links, i need to store them in array & need to open one-by-one in new-tabs.

<

#include <IE.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <ArrayDisplayInternals.au3>
#include <InetConstants.au3>
#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <Inet.au3>
#include <File.au3>
#include <Date.au3>
#include <Misc.au3>
#include <Debug.au3>


Global $ProductName
Global Const $ie_newtab = 0x0800
Global  $arr[30]

; open Flexlink Website in Internet Explorer
$oIE1 = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A")
_IELoadWait($oIE1, 1, 1)

$sHtmlpag = _IEBodyReadHTML($oIE1)

Global $oInputs = _IETagNameGetCollection($oIE1, "a")

Global $array = StringRegExp($oInputs, "More information", $STR_REGEXPARRAYGLOBALFULLMATCH)
_ArrayDisplay($array)

        For $oInput In $oInputs
            if $oInput.title = "More information" then
                Global $oIELink = $oInput

            ExitLoop
            endif
        Next

        MsgBox($MB_SYSTEMMODAL, "Product Name", $oIELink.href)

    Global $oIE2 = _IECreateTab ($oIE1, $oIELink.href)

    Func _IECreateTab (ByRef $oIE, $url)
        Local $Count = 0, $oIE2
        $oIE.Navigate ($url, $ie_newtab)
        $oIE2 = _IEAttach($url, "url")
        _IELoadWait ($oIE2, 300)
        return $oIE2
    EndFunc

Send("#{LEFT}", 0)
;Send("{enter}")

MsgBox($MB_SYSTEMMODAL, "Chains and Accessories", $oIELink.title)
Sleep(4000)
Send("^w")
Sleep(3000)

Func Terminate()
    Exit 0

EndFunc  

>

 

 

The above is not working for me :( 

 

 

Link to comment
Share on other sites

when you point in here  

_IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A")

return  web page

The session is invalid or has expired, please login again. Redirecting to login page in 10 seconds...

 

My FlexLink

you must  automate  a login first  , and  after navigate , in  this link

$oIE1 = _IENavigate("http://repl.flexlink.com/os/products.htm?clicktype=A")
_IELoadWait($oIE1, 1, 1)

not use  send

study  the  udf   _IE  , you find in  help   F1 

Link to comment
Share on other sites

i just show you how  to catch  link  ,  and  store in array .

Don't concern,  try ...., do  mistake,  .... learn , increase your skill , me  and Forum   we will happy to help you , you  have  just a good  example for  what you do , study  ...

Link to comment
Share on other sites

The following should work without an array (untested).

#include <IE.au3>
Const $navOpenInNewTab = 0x0800
Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A", 1)
_IELoadWait($oIE)
Local $oLinks = _IETagNameGetCollection($oIE, "a")
For $oLink In $oLinks
    If $oInput.title = "More information" Then
        $oIE.Navigate2($oInput.href, $navOpenInNewTab)
    EndIf
Next

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...