OpenSSL VPN Serveurs de messagerie |
CUrl/ScénarioDidentificationEtDeRécupérationDesFichiersLe scénario ci-dessous consiste à s'identifier sur le site d' investir pour y télécharger l'hebdomadaire au format éléctronique disponible dès le Vendredi soir. La problématique consistait à conserver les cookies de sessions et à analyser la page contenant les noms des fichiers à télécharger. Les étapes sont :
' GetInvestir.vbs ' Script permettant la récupération par script de ' l'ensemble des fichiers PDF du magazine investir ' Const ForReading = 1 Const WindowStyle = 10 set objFS=CreateObject("Scripting.FileSystemObject") Set objShell = WScript.CreateObject ("WSCript.shell") Set regEx = New RegExp objShell.run "curl -c cookie.txt -G ""www.investir.fr""",WindowStyle,true objShell.run "curl -b cookie.txt -c cookie.txt -d ""login=INDETIFIANT&password=MOTDEPASSE"" www.investir.fr/log_membre.phtml",WindowStyle,true objShell.run "curl -b cookie.txt -G ""www.investir.fr/club_investir/hebdo_pdf.phtml"" -o hebdo_pdf.phtml",WindowStyle,true Set objFile = objFS.OpenTextFile("hebdo_pdf.phtml", ForReading, True) strHTML = objFile.ReadAll regEx.Pattern = "telechargement_pdf.phtml\?(?:type=\D+&|)f=((page|cote)_\d+.pdf)&c=\d+&z=\d+" regEx.IgnoreCase = True regEx.Global = True Set Matches = regEx.Execute(strHTML) For Each Match in Matches wscript.echo "Getting page "&Match.SubMatches(0)&" ..." objShell.run "curl -b cookie.txt -G ""www.investir.fr/club_investir/"&Match.Value&""" -o "&Match.SubMatches(0),WindowStyle,true Next C:\Temp>GetInvestir.vbs L'ensemble des fichiers PDF est maintenant disponible dans le répertoire courant. ' FusionPDF.vbs ' Script de fusion des fichiers PDF d'investir ' Il est arrivé qu'il manque par erreur un fichier PDF c'est pourquoi ' La fusion de fait par itération sur les 55 noms de fichiers possibles Const DOC_FOLDER = "C:\Temp\" Set Acroapp = CreateObject("AcroExch.App") Acroapp.Hide Set avCodeFile = CreateObject("AcroExch.AVDoc") Set avFormCapture = CreateObject("AcroExch.AVDoc") set objFSO = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("WScript.Shell") ' Page_XX.pdf iFile=1 iPage=1 strFilename = DOC_FOLDER & "page_"&right("0"&iFile,2)&".pdf" do while iFile<55 if objFSO.FileExists(strFilename) then wscript.echo strFilename if iPage=1 then avCodeFile.Open strFilename, "Investir.pdf" Set pdCodeFile = avCodeFile.GetPDDoc else avFormCapture.Open strFilename, "" Set pdFormCapture = avFormCapture.GetPDDoc Set AVPage = avCodeFile.GetAVPageView pdCodeFile.InsertPages iPage-2, pdFormCapture, 0, 1, 0 pdFormCapture.Close avFormCapture.Close 1 Set pdFormCapture = Nothing end if iPage=iPage+1 end if iFile=iFile+1 strFilename = DOC_FOLDER & "page_"&right("0"&iFile,2)&".pdf" loop ' Cote_XX.pdf iFile=1 strFilename = DOC_FOLDER & "Cote_"&right("0"&iFile,2)&".pdf" do while iFile<55 if objFSO.FileExists(strFilename) then wscript.echo strFilename avFormCapture.Open strFilename, "" Set pdFormCapture = avFormCapture.GetPDDoc Set AVPage = avCodeFile.GetAVPageView pdCodeFile.InsertPages iPage-2, pdFormCapture, 0, 1, 0 pdFormCapture.Close avFormCapture.Close 1 Set pdFormCapture = Nothing iPage=iPage+1 end if iFile=iFile+1 strFilename = DOC_FOLDER & "Cote_"&right("0"&iFile,2)&".pdf" loop Set pdDoc = avCodeFile.GetPDDoc pdDoc.Save 1, DOC_FOLDER&"\Investir.pdf" pdCodeFile.Close avCodeFile.Close 0 'Exit Acrobat Acroapp.Exit |