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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Sub DecodeUrl()
Dim l_Url As String
Dim tArea(50) As String, tZone(50) As String, nbZone As Integer
Dim texte As String, noDept As String, txt As String
Dim area As String, zone As String
Dim i As Long, j As Long, k As Long
[A1] = "56"
noDept = [A1]
l_Url = "http://s599720764.onlinehome.fr/cartocistes/cartographie" & noDept & "/indexOrdi.php?codeRegion=" & noDept & "&codePays=FR"
texte = GetCodeSource(l_Url) 'avec les balises(format html)
' Boucle recherche <area shape="poly" coords=
j = 1
Do
j = InStr(j, texte, "<area shape=""poly"" coords=")
If j = 0 Then Exit Do
txt = Mid(texte, j, 200)
j = j + Len("<area shape=""poly"" coords=") + 1
k = InStr(j, texte, """")
If k > 0 Then
txt = Mid(texte, k, 50) 'Sauter jusqu'à la 1ère zone
If InStr(1, txt, "href") Then
nbZone = nbZone + 1
area = Mid(texte, j, k - j)
tArea(nbZone) = area
' Recherche alt= pour nom de la zone
j = k
j = InStr(j, texte, "alt=")
If j > 0 Then
j = j + 5
k = InStr(j, texte, """")
If k > 0 Then
zone = Mid(texte, j, k - j)
' Pour debug
Range("B" & nbZone) = zone
'' Range("G" & nbZone) = DecodeUTF8(zone)
Range("G" & nbZone) = RemplaceUTF(zone)
End If
End If
End If
End If
Loop While j > 0
End Sub
Function RemplaceUTF(ByVal chaine As String) As String
ReDim a_remplacer(0 To 29)
ReDim remplacants(0 To 29)
Dim i As Byte
a_remplacer = Array("î", "é", "â", "Ã", "ù", "â", "è", "à ", "â", "â¬", "®", "Ã", "°", "ç", "ô", _
"«", "»", "û", "ê", "â¦", "/ø", "ø", "Ã", "Ã", "Ã", " à ", "Ã", "ë", "â??")
remplacants = Array("î", "é", Chr(26), "Ü", "û", "â", "è", "à", "'", "", "®", "Ø", "°", "ç", "ô", _
Chr(34), Chr(34), "û", "ê", "..", "ø", "ø", "A", "E", "E", " à ", "Ö", "ë", "d'")
For i = 0 To 28
chaine = Replace(chaine, a_remplacer(i), remplacants(i))
Next i
RemplaceUTF = chaine
End Function
Public Function GetCodeSource(sURL)
Dim Lapage_en_HTML 'variable pour l'object "Microsoft.XMLHTTP"( l'object XML)
Set Lapage_en_HTML = CreateObject("Microsoft.XMLHTTP") 'instancie l'object
Lapage_en_HTML.Open "GET", sURL 'ouvre l'url dans l'object
Lapage_en_HTML.Send
Do: DoEvents: Loop While Lapage_en_HTML.ReadyState <> 4 'attendre que la page soit chargée
'le code source est dans """"Lapage_en_HTML.ResponseText""""
'on créé un object "htmlfile"
With CreateObject("htmlfile")
'on y ecrit le codesource complet
.Write Lapage_en_HTML.ResponseText
End With
GetCodeSource = Lapage_en_HTML.ResponseText
End Function |
Partager