Что нового

[Автоматизация] For Next отрабатывает только 1 раз

gloss

Ленивое кодило
Сообщения
155
Репутация
5
Не получается прогнать в цикле все страницы.
Вместо этого проезжает первую и выходит.
Код:
#include <String.au3>
Global $oHTTP, $oURL, $oUA, $oCookie, $P = 1
$oCookie = ''
$oUA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'
;~ $oURL = 'https://steamcompanion.com/gifts/index.php?page=' & $P
$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", url($P))

$oHTTP.SetRequestHeader("User-Agent", $oUA)
$oHTTP.SetRequestHeader("Cookie", $oCookie)
$oHTTP.Send()
$oHTTP.WaitForResponse
$Response = $oHTTP.ResponseText

$start = '<!-- google_ad_section_start -->'
$end = '<!-- google_ad_section_end -->'

$div = _StringBetween($Response, $start, $end)
$last = _StringBetween($Response, "<li class='arrow'><a href='/gifts/index.php?page=", "'>&raquo;</a></li>") 

ConsoleWrite('СТРАНИЦ: ' & $last[0] & @CR & @CR)

For $i = 1 To $last[0]
	
	ConsoleWrite('НАЧАЛО' & @CR & url($P) & @CR & @CR)
	
	$oHTTP.Open("POST", url($P))
	ConsoleWrite('Open: ' & url($P) & @CR)
	$oHTTP.SetRequestHeader("User-Agent", $oUA)
	$oHTTP.SetRequestHeader("Cookie", $oCookie)
	$oHTTP.Send()
	ConsoleWrite('Send' & @CR)
	$oHTTP.WaitForResponse
	$Response = $oHTTP.ResponseText
	ConsoleWrite('Response' & @CR)
	
	$start = '<!-- google_ad_section_start -->'
	$end = '<!-- google_ad_section_end -->'

	$div = _StringBetween($Response, $start, $end)
	
	For $i = 0 To UBound($div, 1) - 1
		$sUrl = StringRegExp($div[$i], '(?i)<a href="(.*?)" class=', 3)
		$sImg = StringRegExp($div[$i], '(?i)<img src="(.*?)" alt="(.*?)" width', 3)
		$sCreator = StringRegExp($div[$i], '(?i)<p class="created-by">by <span style="(.*?)">(.*?)</span></p>', 3)
		$sEndsIN = StringRegExp($div[$i], '(?i)<li>(.*?)</li>', 3)
		ConsoleWrite($sUrl[0] & @CR & $sImg[0] & @CR & $sImg[1] & @CR & $sCreator[1] & @CR & $sEndsIN[0] & @CR & $sEndsIN[1] & @CR & @CR)
	Next
	
	ConsoleWrite('КОНЕЦ ' & @CR & url($P) & @CR & @CR)
	$P = $P + 1
Next

ConsoleWrite('ВЫХОД' & @CR)

Func url($P)
    Return 'https://steamcompanion.com/gifts/index.php?page=' & $P
EndFunc


Так работает:
Код:
#include <String.au3>
Global $oHTTP, $oURL, $oUA, $oCookie, $P = 1

$oUA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'
$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", url($P))
$oHTTP.SetRequestHeader("User-Agent", $oUA)
$oHTTP.Send()
$oHTTP.WaitForResponse
$Response = $oHTTP.ResponseText

$start = "<li class='arrow'><a href='/gifts/index.php?page="
$end = "'>&raquo;</a></li>"

$last = _StringBetween($Response, $start, $end) ;получаем номер последней страницы, чтобы знать сколько их всего
ConsoleWrite('СТРАНИЦ: ' & $last[0] & @CR & @CR) 

For $i = 0 To $last[0]								;в цикле отрисовываем ссылки
	ConsoleWrite('СТРАНИЦА: ' & url($P) & @CR)		;
	$P = $P + 1										;
Next												;

ConsoleWrite(@CR & 'ВЫХОД' & @CR)

Func url($P)
    Return 'https://steamcompanion.com/gifts/index.php?page=' & $P
EndFunc
 

firex

AutoIT Гуру
Сообщения
943
Репутация
208
Код:
For $i = 1 To $last[0]

Код:
For $i = 0 To UBound($div, 1) - 1

Вас ничего не смущает?

Конкретизирую:
$i
 
Автор
G

gloss

Ленивое кодило
Сообщения
155
Репутация
5
Глупая невнимательность :shok:ops:
Вечером мозги уже не работают.
 
Верх