Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp pattern for retrieving data between 2 Tags

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
0
0
TN
Hi
I need your help about this script.
What I want to do is just get the data between the <title>Data to extracted </title> and <!-Mfunc->Data to be extracted<!--/mfunc-->
So if someone here is kind enough to correct me the syntax pattern to achieve my goal.
Thank you !
Code:
Dim Titre,URL,ie,objFSO,Data,OutPut,objRegex,Match,Matches
	Titre = "Notification de Giveawayoftheday © Hackoo © 2013"
	URL = "[URL unfurl="true"]http://fr.giveawayoftheday.com/"[/URL]
	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 : [URL unfurl="true"]http://fr.giveawayoftheday.com/[/URL]  ?",VBYesNO+VbQuestion,Titre)
    If Question = VbYes then
        Ws.Run "[URL unfurl="true"]http://fr.giveawayoftheday.com/",1,False[/URL]
    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
 
I'd go with geates eminently sensible suggestion of using the DOM

Question = MsgBox(ie.document.getElementsByTagName("title")(0).innerText & vbCr & vbCr & " Le temps restant est :" & vbCr & vbCr & ie.document.getElementsByTagName("!")(11).nextSibling.Data & vbCr & vbCr & "Voulez-vous accéder au site : ?", vbYesNo + vbQuestion)
 
Thank you for all your reply !
So i solved the problem like this :
Code:
Option Explicit
Dim Titre,URL,ie,Ws,Question,Data,objRegex,Match,Matches,i
	Titre = "Notification de Giveawayoftheday © Hackoo © 2013"
	URL = "[URL unfurl="true"]http://fr.giveawayoftheday.com/"[/URL]
	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 : ""[URL unfurl="true"]http://fr.giveawayoftheday.com""[/URL] ?",VBYesNO+VbQuestion,Titre)
    If Question = VbYes then
        Ws.Run "[URL unfurl="true"]http://fr.giveawayoftheday.com/",1,False[/URL]
    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
 
I think you are making a mistake, but if it works for you then hurrah.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top