Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
AutoIt Version : 3.3.12.0
Auteur: Pandi_Panda
Fonction du Script :
Modèle de Script AutoIt.
#ce ----------------------------------------------------------------------------
#include <String.au3>
#include <INet.au3>
#include <array.au3>
$adresse_sunnyportal = "http://www.sunnyportal.com/Templates/PublicPage.aspx?page="
$id_samatan = "64f527bf-a75c-4d79-8f96-1177cb130f3d"
$url = $adresse_sunnyportal&$id_samatan ; pandi
Local $cookie = ""
$text_html = _get_source($cookie,$url) ; pandi
$debut_str = 'ZoomDiagramStart' ;=> trouve le "OID" pour les 2 diagramme de la page
$fin_str = '')"'
$array_OID_jour_mois = _StringBetween ($text_html,$debut_str,$fin_str);dans le code html les diagrammes sont dans le meme ordre que sur la page officiel doncle diagramme jour en 1er lediagramme mois en 2eme ... suivant construction de la page
If Not @error Then
$array_OID_jour = StringSplit($array_OID_jour_mois[0],";")
$OID_diagramme_jour = $array_OID_jour[UBound($array_OID_jour)-1];le OID est stocker dans la derniere case du tableau , on le recupere
$adresse_diagramme_jour = "http://www.sunnyportal.com/Templates/DiagrammScaleUp.aspx?TextBoxYear=" & "2014" & "&TextBoxMonth=" & "07" & "&TextBoxDay=" & "04" & "&TextBoxHour=" & "21" & "&TextboxIndex=0&Width="& "1300" & "&Height=" & "450" & "&OID=" & $OID_diagramme_jour ;trouver en analysant le code html des page sma, TextboxIndex=0 pour le premier diagramme de la page officiel et TextboxIndex=1 pour le deuxieme...
$url = $adresse_diagramme_jour
$text_html_diagramme_jour = _get_source2($cookie,$url) ; pandi
$debut_str = 'src="/chartfx70/temp/' ;=> trouve la fin de l'adresse du petit diagramme
$fin_str = '.png'
$array = _StringBetween ($text_html_diagramme_jour,$debut_str,$fin_str)
If Not @error Then
$adresse_telecharge_diagramme_jour = "/chartfx70/temp/" & $array[0] & ".png"
_getImage($cookie,$adresse_telecharge_diagramme_jour,@ScriptDir & "\diagramme test.png")
If Not @error Then
MsgBox(0,"","Diagramme téléchargé.")
Else
MsgBox(64,"error","error 3 "&@CRLF&"error = "&@error)
EndIf
Else
MsgBox(64,"error","error 2"&@CRLF&"error = "&@error)
EndIf
Else
MsgBox(64,"error","error 1"&@CRLF&"error = "&@error)
EndIf
Func _get_source(byref $cookie,$link)
Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET",$url)
$oHTTP.SetRequestHeader("Host", "www.sunnyportal.com")
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0; rv:30.0) Gecko/20100101 Firefox/30.0")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.SetRequestHeader("Accept-Language", "fr,fr-fr;q=0.8")
$oHTTP.SetRequestHeader("Accept-Encoding", "txt")
$oHTTP.Send()
$head = $oHTTP.GetAllResponseHeaders()
Local $str = _StringBetween($head,'Set-Cookie: ',@CRLF)
$cookie = ""
For $i = 0 To UBound($str)-1
$cookie &= $str[$i]&';'
Next
$cookie = StringTrimRight($cookie,1)
Return $oHTTP.Responsetext
EndFunc
Func _get_source2(ByRef $cookie,$link)
Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET",$link)
$oHTTP.SetRequestHeader("Host", "www.sunnyportal.com")
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0; rv:30.0) Gecko/20100101 Firefox/30.0")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.SetRequestHeader("Accept-Language", "fr,fr-fr;q=0.8")
$oHTTP.SetRequestHeader("Accept-Encoding", "txt")
$oHTTP.SetRequestHeader("Cookie", $cookie)
$oHTTP.SetRequestHeader("Connection", "keep-alive")
$oHTTP.Send()
$oHTTP.WaitForResponse
Return $oHTTP.Responsetext
EndFunc
Func _getImage(ByRef $cookie,$link,$pathDl)
TCPStartup()
Local $sIp
If StringRegExp($link,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") Then
$sIp = $url
Else
$sIp = TCPNameToIP('www.sunnyportal.com')
If @error Then MsgBox(0,"",@error)
EndIf
Local $oTCP = TCPConnect($sIp,80)
; conn
Local $sRequest = ""
$sRequest &= 'GET '&$link&' HTTP/1.1'&@CRLF
$sRequest &= 'Host: www.sunnyportal.com'&@CRLF
$sRequest &= 'User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:30.0) Gecko/20100101 Firefox/30.0'&@CRLF
$sRequest &= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'&@CRLF
$sRequest &= 'Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'&@CRLF
$sRequest &= 'Accept-Encoding: gzip, deflate'&@CRLF
$sRequest &= 'Cookie: '&$cookie&@CRLF
$sRequest &= ''&@CRLF
TCPSend($oTCP,$sRequest)
; send
Local $line = TCPRecv($oTCP,1)
Local $txt = ""
While Not @error
$txt &= $line
$line = TCPRecv($oTCP,1)
WEnd
;recv
TCPShutdown()
Local $t = StringSplit($txt,@CRLF&@CRLF,3)
$txt = $t[1]
$txt = StringReplace($txt,"0x00",chr(0))
Local $h = FileOpen($pathDl,16+2)
FileWrite($h,$txt)
FileClose($h)
EndFunc