[..] Echec téléchargement avec IE - pas avec Powershell
Posté : dim. 15 déc. 2019 11:20
Bonjour.
Je vous explique en détail mon souci, avant de vous mettre le script...
Je télécharge souvent des logiciels, avec les fonctions d'IE (AutoIt), afin de les télécharger quand j'en ai besoin...
Un seul logiciel me pose problème : la version "alpha" de captvty.
site : http://v3.captvty.fr/
D'habitude :
- J'utilise _IECreate et _IELinkGetCollection pour lister les liens de cette page web.
- Puis une condition afin d'avoir uniquement le lien qui se finit en .zip, le lien du fichier par conséquent...
- et j'enchaine par un InetGet pour télécharger le dit fichier...
Sauf que là, malgré mes tests, même si l'extension se finit en .zip, si je l'ouvre avec un éditeur de texte : en fait, c'est un fichier HTML...
Puis, je me suis dit - par curiosité, avant de laisser tomber - et si je faisais cette méthode, via en ligne de commande...
Et vu que je voulais commencer Powershell, c'est le moment d'essayer...
Et donc :
- j'ai listé les liens avec powershell
- je récupère le lien
- je commence le téléchargement.
Et.... ça fonctionne...
Alors que j'ai fait pratiqué la même 'procédure'.
Voici le script :
Pouvez-vous me dire pourquoi, avec IE, ça coince ?
Merci.
++
Je vous explique en détail mon souci, avant de vous mettre le script...
Je télécharge souvent des logiciels, avec les fonctions d'IE (AutoIt), afin de les télécharger quand j'en ai besoin...
Un seul logiciel me pose problème : la version "alpha" de captvty.
site : http://v3.captvty.fr/
D'habitude :
- J'utilise _IECreate et _IELinkGetCollection pour lister les liens de cette page web.
- Puis une condition afin d'avoir uniquement le lien qui se finit en .zip, le lien du fichier par conséquent...
- et j'enchaine par un InetGet pour télécharger le dit fichier...
Sauf que là, malgré mes tests, même si l'extension se finit en .zip, si je l'ouvre avec un éditeur de texte : en fait, c'est un fichier HTML...
Puis, je me suis dit - par curiosité, avant de laisser tomber - et si je faisais cette méthode, via en ligne de commande...
Et vu que je voulais commencer Powershell, c'est le moment d'essayer...
Et donc :
- j'ai listé les liens avec powershell
- je récupère le lien
- je commence le téléchargement.
Et.... ça fonctionne...
Alors que j'ai fait pratiqué la même 'procédure'.
Voici le script :
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Global $oIE
$dossiertmp = @DesktopDir & '\captvtytmp'
DirRemove($dossiertmp, 1)
DirCreate($dossiertmp)
_captvty_alpha_powershell()
_captvty_alpha_IE()
ShellExecute($dossiertmp)
Func _captvty_alpha_powershell()
$acceuil = 'http://v3.captvty.fr/'
$captvty_a_ps_zip = $dossiertmp & '\captvty_alpha_pshell.zip'
Local $sText, $lien_zip
$cmd = '(Invoke-WebRequest -Uri "' & $acceuil & '"https://v3.captvty.fr/").Links | sort-object href -Unique | Format-List innerText, href'
$commande = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd
$pid = Run($commande, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
StdinWrite($pid)
$sSTDOUT = ""
While 1
$sOutput = StdoutRead($pid)
If @error Then ExitLoop
If $sOutput <> "" Then
$sText &= $sOutput & @CRLF
EndIf
WEnd
If $sText <> '' Then
For $a = 1 To StringSplit($sText, @LF)[0]
$ligne = StringSplit($sText, @LF)[$a]
If StringInStr($ligne, '.zip') Then $lien_zip = 'https:' & StringStripWS(StringReplace(StringReplace($ligne, ':', ''), 'href', ''), 8)
Next
EndIf
$cmd_2 = 'Invoke-WebRequest -Uri "' & $lien_zip & '" -OutFile "' & $captvty_a_ps_zip
$commande_2 = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd_2
RunWait($commande_2, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
EndFunc ;==>_captvty_alpha_powershell
Func _captvty_alpha_IE()
$acceuil = 'http://v3.captvty.fr/'
$captvty_a_ie_zip = $dossiertmp & '\captvty_alpha_IE.zip'
Local $sText, $lien_zip
Local $oIE = _IECreate($acceuil)
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended
For $oLink In $oLinks
If StringRight($oLink.href, 4) = '.zip' Then $lien_zip = $oLink.href
Next
$myDL = InetGet(StringStripWS($lien_zip, 8), $captvty_a_ie_zip, 1, 1)
Do
Sleep(250)
Until InetGetInfo($myDL, 2) ; Check if the download is complete.
Local $nBytes = InetGetInfo($myDL, 0)
InetClose($myDL) ; Close the handle to release resources.
;~ $cmd_2 = 'Invoke-WebRequest -Uri "' & $lien_zip & '" -OutFile "' & $captvty_a_ie_zip
;~ $commande_2 = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd_2
;~ RunWait($commande_2, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
EndFunc ;==>_captvty_alpha_IE
;~ Func _FindBetweenString($Line, $char1, $char2)
;~ $part1 = StringRegExpReplace($Line, '^.*' & $char1, '')
;~ $Term = StringRegExpReplace($part1, '\' & $char2 & '.*', '')
;~ Return SetExtended(1, $Term)
;~ EndFunc ;==>_FindBetweenString
#include <WindowsConstants.au3>
#include <IE.au3>
Global $oIE
$dossiertmp = @DesktopDir & '\captvtytmp'
DirRemove($dossiertmp, 1)
DirCreate($dossiertmp)
_captvty_alpha_powershell()
_captvty_alpha_IE()
ShellExecute($dossiertmp)
Func _captvty_alpha_powershell()
$acceuil = 'http://v3.captvty.fr/'
$captvty_a_ps_zip = $dossiertmp & '\captvty_alpha_pshell.zip'
Local $sText, $lien_zip
$cmd = '(Invoke-WebRequest -Uri "' & $acceuil & '"https://v3.captvty.fr/").Links | sort-object href -Unique | Format-List innerText, href'
$commande = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd
$pid = Run($commande, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
StdinWrite($pid)
$sSTDOUT = ""
While 1
$sOutput = StdoutRead($pid)
If @error Then ExitLoop
If $sOutput <> "" Then
$sText &= $sOutput & @CRLF
EndIf
WEnd
If $sText <> '' Then
For $a = 1 To StringSplit($sText, @LF)[0]
$ligne = StringSplit($sText, @LF)[$a]
If StringInStr($ligne, '.zip') Then $lien_zip = 'https:' & StringStripWS(StringReplace(StringReplace($ligne, ':', ''), 'href', ''), 8)
Next
EndIf
$cmd_2 = 'Invoke-WebRequest -Uri "' & $lien_zip & '" -OutFile "' & $captvty_a_ps_zip
$commande_2 = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd_2
RunWait($commande_2, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
EndFunc ;==>_captvty_alpha_powershell
Func _captvty_alpha_IE()
$acceuil = 'http://v3.captvty.fr/'
$captvty_a_ie_zip = $dossiertmp & '\captvty_alpha_IE.zip'
Local $sText, $lien_zip
Local $oIE = _IECreate($acceuil)
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended
For $oLink In $oLinks
If StringRight($oLink.href, 4) = '.zip' Then $lien_zip = $oLink.href
Next
$myDL = InetGet(StringStripWS($lien_zip, 8), $captvty_a_ie_zip, 1, 1)
Do
Sleep(250)
Until InetGetInfo($myDL, 2) ; Check if the download is complete.
Local $nBytes = InetGetInfo($myDL, 0)
InetClose($myDL) ; Close the handle to release resources.
;~ $cmd_2 = 'Invoke-WebRequest -Uri "' & $lien_zip & '" -OutFile "' & $captvty_a_ie_zip
;~ $commande_2 = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ' & $cmd_2
;~ RunWait($commande_2, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
EndFunc ;==>_captvty_alpha_IE
;~ Func _FindBetweenString($Line, $char1, $char2)
;~ $part1 = StringRegExpReplace($Line, '^.*' & $char1, '')
;~ $Term = StringRegExpReplace($part1, '\' & $char2 & '.*', '')
;~ Return SetExtended(1, $Term)
;~ EndFunc ;==>_FindBetweenString
Pouvez-vous me dire pourquoi, avec IE, ça coince ?
Merci.
++