View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
sal21 sal21 is offline
external usenet poster
 
Posts: 18
Default find string in web page

Hi Ron tks for reply....
But i am a newbie how can use the function? wath is the correct sintyax if i
want use in my original code?How to store the "827" in a Var?
Tks from Napoli.

Note: Yes the word is "Trovati" and not "Trovati:", sorry me.

"Ron Rosenfeld" wrote:

On Fri, 7 Dec 2007 13:59:01 -0800, sal21
wrote:

Now have a little other qst:

I have this web page attached, i want to find the word "Trovati:" and get
the value near tath in this case is: 827 , after store 827 in a cell of sheet.
tath is all.
Note:already have a VBA code to naviate in web page.


I note that the string "Trovati:" is NOT in the web page you posted, although
the string "Trovati" is present.

In any event, the following function should look in Src for a phrase (str) and
return the first word in the first phrase that is not enclosed in <....

In your example, if Src is your web page, and str is "Trovati", the function
will return "827".

I'm not sure if it will take into account all of the possible variations in
context, so be sure to test it thoroughly.

========================================
Option Explicit
Function GetDataAfter(Src As String, str As String) As String
'Src is the page being searched
'str is the string to be found within that page
'returns the first word in a string following str that is not within a tag

Dim re As Object
Dim mc As Object
Dim sPat As String

sPat = str & "[\s\S]*?(<[\s\S]*?)*(\S+)"

Set re = CreateObject("vbscript.regexp")
With re
.Pattern = sPat
.Global = True
.ignorecase = True
End With

If re.test(Src) = True Then
Set mc = re.Execute(Src)
GetDataAfter = mc(0).submatches(1)
End If
End Function
==============================
--ron