Précédent   Forum du club des développeurs et IT Pro > Autres langages > Général Visual Basic 6 et VBScript > VBScript
VBScript Le forum d'entraide sur VBScript. Avant de poster -> La FAQ VBScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 02/01/2013, 19h33   #1
hackoofr
Expert Confirmé
 
Avatar de hackoofr
 
Homme Mehdi Tounisiano
Enseignant
Inscription : juin 2009
Messages : 1 631
Détails du profil
Informations personnelles :
Nom : Homme Mehdi Tounisiano
Âge : 38
Localisation : Tunisie

Informations professionnelles :
Activité : Enseignant

Informations forums :
Inscription : juin 2009
Messages : 1 631
Points : 3 692
Points : 3 692
Par défaut Motif d'une RegExp pour extraire des données entre 2 Balises


Je sollicite votre aide a propos de ce script.
Ce que je veux faire c'est juste récupérer les données comprises entre les balises <title>Données à extraire</title> et <!--mfunc-->Données à extraire<!--/mfunc-->
Donc si quelqu'un ici parmi vous a la gentillesse de me corriger la syntaxe du Motif afin d'atteindre mon but.

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
33
34
35
Dim Titre,URL,ie,objFSO,Data,OutPut,objRegex,Match,Matches
    Titre = "Notification de Giveawayoftheday © Hackoo © 2013"
    URL = "http://fr.giveawayoftheday.com/"
    Set ie = CreateObject("InternetExplorer.Application")
    Set Ws = CreateObject("wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ie.Navigate (URL)
    ie.Visible=false
    DO WHILE ie.busy
        wscript.sleep 100
    LOOP
    Data = ie.document.documentElement.innerHTML
    ie.Quit
    Question = MsgBox(RegExp("<title>(.*?)</title>")&vbcr&vbcr&_
    " Le temps restant est :" &vbcr&vbcr&_
    RegExp("<!--mfunc-->(.*?)<!--/mfunc-->")&vbcr&vbcr&_
    "Voulez-vous accéder au site : http://fr.giveawayoftheday.com/  ?",VBYesNO+VbQuestion,Titre)
    If Question = VbYes then
        Ws.Run "http://fr.giveawayoftheday.com/",1,False
    else
        Wscript.Quit
    end if
    Set ie = Nothing
 
Function RegExp(Motif)    
Set objRegex = new RegExp
objRegex.Pattern = Motif 'Motif pour y extraire le code source
objRegex.Global = False 'une seule instance
objRegex.IgnoreCase = True 'Ignorer la casse
Set Matches = objRegex.Execute(Data) 'Execution du la RegExp
For Each Match in Matches  
    strMatchValue = Match.Value
    RegExp = strMatchValue
Next
End Function
hackoofr est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/01/2013, 21h13   #2
hackoofr
Expert Confirmé
 
Avatar de hackoofr
 
Homme Mehdi Tounisiano
Enseignant
Inscription : juin 2009
Messages : 1 631
Détails du profil
Informations personnelles :
Nom : Homme Mehdi Tounisiano
Âge : 38
Localisation : Tunisie

Informations professionnelles :
Activité : Enseignant

Informations forums :
Inscription : juin 2009
Messages : 1 631
Points : 3 692
Points : 3 692

Problème
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
33
34
35
36
37
38
39
40
Option Explicit
Dim Titre,URL,ie,Ws,Question,Data,objRegex,Match,Matches,i
    Titre = "Notification de Giveawayoftheday © Hackoo © 2013"
    URL = "http://fr.giveawayoftheday.com/"
    Set ie = CreateObject("InternetExplorer.Application")
    Set Ws = CreateObject("wscript.Shell")
    ie.Navigate(URL)
    ie.Visible=false
    DO WHILE ie.busy
        wscript.sleep 100
    LOOP
    Data = ie.document.documentElement.innerHTML
    ie.Quit
    Set ie = Nothing
    Question = MsgBox(RegExp("<title>(.*)</title>",Data)& vbcr & vbcr &_
    " Le temps restant est : " & RegExp("<!--mfunc-->(.*)<!--/mfunc-->",Data)& vbcr & vbcr &_
    "Voulez-vous accéder au site : ""http://fr.giveawayoftheday.com"" ?",VBYesNO+VbQuestion,Titre)
    If Question = VbYes then
        Ws.Run "http://fr.giveawayoftheday.com/",1,False
    else
        Wscript.Quit
    end if
 
Function RegExp(Motif,Data)     
 Set objRegex = new RegExp
 objRegex.Pattern = Motif  
 objRegex.Global = False 'une seule instance  
 objRegex.IgnoreCase = True 'Ignorer la casse  
 Set Matches = objRegex.Execute(Data)  
 If Matches.Count > 0 Then
      Set Match = Matches(0)
   If Match.SubMatches.Count > 0 Then
        For i = 0 To Match.SubMatches.Count-1
            RegExp = Match.SubMatches(i)
        Next
    End If
 End If
 Set Matches = Nothing  
 Set objRegex = Nothing  
End Function
hackoofr est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 04h33.


 
 
 
 
Partenaires

Hébergement Web