faustf Posted August 3, 2018 Share Posted August 3, 2018 (edited) hi guy i have the script inside of them have a function this function have a do until dimplie a variable decreases till arrive at zero, at zero must be exit , i insert inside of loop a consolwrite and look the variable arrive at zero and start in negative , but not exit why ?? expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: faustf Script Function: Macro per usare Amazon come venditore non professionale #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;#cs #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf ;#ce Global $iGTimeToCeck = "1000", $iGTimeOut = "1000" Local $urlAmaS = "https://www.amazon.it/s/ref=nb_sb_noss?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=" ;Local $urlAmaS = "https://www.amazon.it/s/ref=sr_nr_p_76_0?fst=as%3Aoff&rh=n%3A425916031%2Cn%3A460080031%2Cn%3A460126031%2Ck%3Ai7%2Cp_76%3A490211031%7C490210031&keywords=i7&ie=UTF8&qid=1489074068&rnid=490209031" ; con opzione attiva amazon prime e spedizione gratis ;Local $urlAmaS = "https://www.amazon.it/s/ref=sr_st_price-asc-rank?keywords=" ; prima parte url per prezzo crescente Local $sLUrl2 = "&__mk_it_IT=%C3%85M%C3%85Z%C3%95%C3%91&rh=i%3Aaps%2Ck%3A0190198457509&qid=1533231546&sort=price-asc-rank" ; opzione prezzo crescente Global $sUrlAtom1 = "https://www.amazon.it/s/ref=sr_pg_" Local $sLuser = "@gmail.com" Local $sLpass = "" _Amazon_Search("TN329BK", $urlAmaS) ;_Amazon_Search("5032037108591", $urlAmaS) ;_Amazon_Search("iphone x", $urlAmaS) Func _Amazon_Search($frases, $url, $Hide = 0, $slow = 0) If $Hide = 0 Then $Hide = 1 EndIf If $slow = 0 Then $slow = 1000 EndIf Global $oIE = _IECreate($url & $frases & $sLUrl2, 0, $Hide, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE) Sleep($slow) Local $sText = _IEBodyReadText($oIE) Local $iFindBadPage = StringInStr($sText, "This page can’t be displayed") If $iFindBadPage <> 0 Then If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running. ProcessClose("iexplore.exe") EndIf Sleep($slow) $oIE = _IECreate($url & $frases, 0, $Hide, 1, 1) ; <--- 0011 invisible explorer <--- 0111 visible explorer _IELoadWait($oIE, $iGTimeToCeck, $iGTimeOut) EndIf Local $sLHtml = _IEBodyReadHTML($oIE) Local $sLText = _IEBodyReadText($oIE) If StringInStr($sLText, "non coincide con alcun prodotto") = 0 Then MsgBox(0,'','sono qui') FileDelete (@ScriptDir & "\TEMP\Amazon.html") _True_write_File(@ScriptDir & "\TEMP\Amazon.html", $sLHtml) ;MsgBox(0, '', 'modifico la pagina web') _FileDeleteLine(@ScriptDir & '\TEMP\Amazon.html', 'Articoli visualizzati di recente e suggerimenti in primo piano', '', 'end') Local $hLFileOP = FileOpen(@ScriptDir & "\TEMP\Amazon.html", $FO_READ) Local $sLFileRead = FileRead($hLFileOP) ;Local $aL = StringRegExp($sLHtml, 'href="(.*?)"><img src="(.*?)" srcset="(.+?)title="(.*?)" href="', 3) ;_ArrayDisplay($aL) ;Local $aL1 = StringRegExp($sLHtml, '(?s)href="([^"]+)"><img src="([^"]+)"\h*srcset="[^"]+.*?title="([^"]+)" href="', 3) MsgBox(0,'','sono qui2') Local $sLPagSuccessiva = StringRegExp($sLFileRead, '<span id="pagnNextString">(.*?)</span>', 3) If IsArray($sLPagSuccessiva) Then ; controlla se ci sono piu pagine Local $aLAddres2Page = StringRegExp($sLFileRead, '<a href="\/s\/ref=sr_pg_2(.*?)">2<\/a>', 3) MsgBox(0,'','sono qui3') If IsArray($aLAddres2Page) Then Local $aLAddres2PageSplit1 = StringRegExp($aLAddres2Page[0], '(.*?)page', 3) Local $aLAddres2PageSplit2 = StringRegExp($aLAddres2Page[0], 'page=2(.*?)$', 3) Local $aL2 = StringRegExp($sLFileRead, 'text-bold">EUR (.*?)</span></a><span class=', 3) ;Local $aL = StringRegExp($sLHtml, 'cfMarker" alt="(.*?)" src="', 3) Local $aL = StringRegExp($sLFileRead, 'cfMarker" alt=(.*?) src="', 3) ConsoleWrite($sLFileRead) _ArrayDisplay($aL2) _ArrayDisplay($aL) _ArrayDisplay($aLAddres2Page) _ArrayDisplay($aLAddres2PageSplit1) _ArrayDisplay($aLAddres2PageSplit2) Else MsgBox(16, 'Errore', 'Problema con regexp url $aLAddres2Page ') EndIf Else ; se ce una pagina solo MsgBox(0, 'Info', 'non ci sono piu pagine') EndIf _ArrayDisplay($sLPagSuccessiva) Else MsgBox(0, 'Info', 'non coincide con alcun prodoto ' & $frases) EndIf #cs Local $oBtns = $oIE.document.GetElementsByTagName("input") For $oBtn In $oBtns $name = String($oBtn.id()) $buttonOK = String($oBtn.type()) If $name = "twotabsearchtextbox" Then _IEAction($oBtn, "click") _IEFormElementSetValue($oBtn, $frases) EndIf If $buttonOK = "submit" Then _IEAction($oBtn, "click") EndIf Next #ce EndFunc ;==>_Amazon_Search ; #INDEX# ======================================================================== ; Title .........: GUI_Configure.au3 ; AutoIt Version : 3.3.14.2++ ; Language ......: Italian ; Description ...: A collection of Function for Logic of Gest ; Author ........: Faustf ; What do you do.: Write data in File ; Version .......: 0.0.1 BETA - Work in progress 15/03/2016 ; Syntax ........: ; ================================================================================ Func _True_write_File($sFilePath, $sDataWrite, $iReturn = 0) If $iReturn = Default Then $iReturn = 0 $File = FileOpen($sFilePath, 1) If $iReturn = 0 Then FileWrite($File, $sDataWrite & @CRLF) Else FileWrite($File, $sDataWrite) EndIf FileClose($File) EndFunc ;==>_True_write_File ; #INDEX# ========================================================================================================================= ; Title .........: UDF_Plus.au3 ; AutoIt Version : 3.3.14.2++ ; Language ......: Italian ; Description ...: A collection of Function ; Author ........: Faustf ; What do you do.: delete a line inside of file ; Version .......: 0.0.1 BETA - Work in progress 13/06/2018 ; Syntax ........: _FileDeleteLine($path, $match, $start, $to) path of file + word to $match, when find it erase all line. ; ...............: or you can use $match + $to if you want erase a range of line or $start + $to if you want erase a range ; ...............: of line. You can use a word "end" if you want erase line at end of file ; Example .......: _FileDeleteLine(@ScriptDir & '\TEMP\test.txt', '<div class="container table-wrap">', '0', '20') ; ...............: _FileDeleteLine(@ScriptDir & "\TEMP\test.txt", 0, 1, "end") ; ...............: _FileDeleteLine(@ScriptDir & '\TEMP\test.txt', '', '2', '133') ; Error Retrun ..: txtopenko = when is not possible open a file ; ...............: Error 1 = when insert a number of line , you have this error. ; ...............: You must use a difference from first point to arrive point ; ================================================================================================================================= Func _FileDeleteLine($path, $match, $start, $to) Local $file_count_lines = _FileCountLines($path) If $file_count_lines = 0 Then Return "txtopenko" If $to = "end" Then $to = $file_count_lines EndIf Select Case $start = 0 And $to = "" And $match = "" ; cancel only match word finded Local $aLText = FileReadToArray($path) ;_ArrayDisplay($aLText) For $i = 0 To UBound($aLText) - 1 If StringInStr($aLText[$i], $match) Then _ArrayDelete($aLText, $i) EndIf Next _FileWriteFromArray($path, $aLText) Case $start = 0 And $to <> "" And $match <> "" ; cancel from word finded till $to Local $iLCtrlDO = 1 Local $aLText = FileReadToArray($path) Local $aLTextClone = FileReadToArray($path) ;_ArrayDisplay($aLText) For $i = 0 To UBound($aLText) - 1 If StringInStr($aLText[$i], $match) Then $iLCtrlDO = $i Do _ArrayDelete($aLTextClone, $iLCtrlDO) $to -= 1 ConsoleWrite($to & @CRLF) Until $to = 0 EndIf Next _FileWriteFromArray($path, $aLTextClone) Case $start <> 0 And $to <> "" And $match = "" ; cancel from $start till $to (also with "end" special-word) If $to = $file_count_lines Then Local $aLText = FileReadToArray($path) Local $aLTextClone = FileReadToArray($path) For $i = 0 To UBound($aLText) - 1 $iLCtrlDO = ($start - 1) Do _ArrayDelete($aLTextClone, $iLCtrlDO) $to -= 1 Until $to = 0 ExitLoop Next _FileWriteFromArray($path, $aLTextClone) Else Local $to1 = $to + $start If $to1 < $file_count_lines Then Local $aLText = FileReadToArray($path) Local $aLTextClone = FileReadToArray($path) For $i = 0 To UBound($aLText) - 1 $iLCtrlDO = ($start - 1) Do _ArrayDelete($aLTextClone, $iLCtrlDO) $to -= 1 Until $to = 0 ExitLoop Next _FileWriteFromArray($path, $aLTextClone) Else Return "Error 1" ;MsgBox(16, "Errore", "Errore probabilmente non hai inserito la differenza ma hai messo direttamente il numero riga e superi con l'inizio il totale righe del foglio") EndIf EndIf EndSelect EndFunc ;==>_FileDeleteLine and this is a part of decrese number in console 4 3 2 1 0 -1 -2 -3 -4 Edited August 3, 2018 by faustf Link to comment Share on other sites More sharing options...
faustf Posted August 3, 2018 Author Share Posted August 3, 2018 (edited) if i insert in until of do < minor or equal <= go correct, but in console write have 3 2 1 0 -1 -2 the cicle do is not accurete, why ? exist an explain ?? ? thankz Edited August 3, 2018 by faustf Link to comment Share on other sites More sharing options...
Danp2 Posted August 3, 2018 Share Posted August 3, 2018 (edited) Your Do loop is inside a For loop. The Do loop does exit (add a consolewrite after the Until to confirm), but then starts again due to the next iteration of the For loop. Edit: Perhaps you intended to reset the value of $to before the Do loop begins? Edited August 3, 2018 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted August 3, 2018 Share Posted August 3, 2018 Also, this code makes no sense to me. For $i = 0 To UBound($aLText) - 1 $iLCtrlDO = ($start - 1) Do _ArrayDelete($aLTextClone, $iLCtrlDO) $to -= 1 Until $to = 0 ExitLoop Next Because of the ExitLoop, it will never execute the outer loop more than once. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
faustf Posted August 3, 2018 Author Share Posted August 3, 2018 ok for no sense of last code , but is strange you dont find? the first ?? , i think before start in loop would be much better if condition control if variable is just ready for go over no ?? or only my sick mind think this? Link to comment Share on other sites More sharing options...
Danp2 Posted August 3, 2018 Share Posted August 3, 2018 It's only doing what you've told it to do. You should look into using a single call to _ArrayDelete instead of looping, like this -- For $i = 0 To UBound($aLText) - 1 If StringInStr($aLText[$i], $match) Then $sRange = String($i) & "-" & String($to) _ArrayDelete($aLTextClone, $sRange) ExitLoop EndIf Next and maybe even replace the For loop with a single call to _ArraySearch. faustf 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
BrewManNH Posted August 3, 2018 Share Posted August 3, 2018 A Do loop will always execute at least once because the test is at the end of the loop. A While loop can execute zero times if the condition is met, because it's tested at the beginning of the loop. faustf 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
faustf Posted August 3, 2018 Author Share Posted August 3, 2018 thankz for support Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now