[VBS] Décomposition d'une adresse URL
:salut:
Je souhaite faire une décomposition d'une adresse URL :
Alors j'ai modifié ce script trouvé ici ==> http://roger.neel.free.fr/langages/c...ubmatches.html
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Option Explicit
Dim adress,result,Title
'*****************************************************************
'Fonction pour ajouter des guillemets dans une variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************************************
Function Search(Pattern,MyString)
Dim objet
Dim correspondance
Dim collection
Set objet = New RegExp
objet.Pattern = Pattern
objet.IgnoreCase = True
objet.Global = True
Set collection = objet.Execute(MyString)
Set correspondance = collection(0)
result = "Protocol = " & DblQuote(correspondance.SubMatches(0)) & VbCRLF & vbCrLf _
& "Domain = " & DblQuote(correspondance.SubMatches(1)) & VbCRLF & vbCrLf _
& "Port = " & DblQuote(correspondance.SubMatches(2)) & vbCrLf & vbCrLf _
& "Folder = " & DblQuote(correspondance.SubMatches(3)) & VbCRLF& vbCrLf _
& "File = " & DblQuote(correspondance.SubMatches(4)) & VbCRLF& vbCrLf _
& "Anchor = "& DblQuote(correspondance.SubMatches(5))
Search = result
End Function
'*****************************************************************
adress = InputBox( "Please input the http or the https address.", " What makes up a Url ?","http://www.lesite.com:8080/coursasp/sommaire.html#ancre")
result = Search("(\w+):\/\/([^/:]+):?(\d*)?\/(.*[^.])\/(\w+.\w+)#?(\w+)?",adress)
Title = "Decomposition of a URL adress"
MsgBox Title & "(Uniform Resource Locator ) ==> URL : " & DblQuote(adress) & vbCrLf & vbCrLf _
& result,64,Title |
Donc, mon problème est quand je tape par exemple une URL = "http://www.google.com" ==> le script me retourne une erreur dans la ligne N°18 "Argument ou procédure incorrecte"
Alors je cherche comment contourner cette erreur ? :koi:
:merci: