Web Query

  • Thread starter Thread starter Daveed
  • Start date Start date
D

Daveed

Hi,

I am trying to perform a webquery that grabs specific data from a page. I
want to grab only the data between two specific tags "<!--StartTag-->" and
"<!--EndTag-->"

Is there any way to do this? The webquery built into excel does not seem to
allow for this kind of specific parsing. Any help would be appreciated.

thanks,
dave
 
Hi Dave,

The following function will take a URL, a start string (in your case, pass
in "<!--StartTag-->"), and an end string ("<!--EndTag-->") and will retun
the HTML source inbetween them. If you want the actual text displayed on
the screen, then you can change InnerHTML to InnerText, but you will have to
use 2 visible text strings (not HTML comments) as the start and end
arguments.

Public Function gsGetString(rsURL As String, _
rsStartHTML As String, rsEndHTML As String) As String
Dim ie As Object
Dim sHTML As String
Dim lStartPos As Long
Dim lEndPos As Long

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Navigate rsURL
Do Until Not .Busy And .ReadyState = 4
DoEvents
Loop
sHTML = .Document.Body.InnerHTML
End With

ie.Quit
Set ie = Nothing

lStartPos = InStr(1, sHTML, rsStartHTML, vbTextCompare)
If lStartPos Then
lStartPos = lStartPos + Len(rsStartHTML)
lEndPos = InStr(lStartPos, sHTML, rsEndHTML, vbTextCompare)
If lEndPos Then
lEndPos = lEndPos - 1
gsGetString = Mid$(sHTML, lStartPos, lEndPos _
- lStartPos + 1)
End If
End If
End Function

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Thanks,

that is precisely what i was looking for!!!

Dave

Jake Marx said:
Hi Dave,

The following function will take a URL, a start string (in your case, pass
in "<!--StartTag-->"), and an end string ("<!--EndTag-->") and will retun
the HTML source inbetween them. If you want the actual text displayed on
the screen, then you can change InnerHTML to InnerText, but you will have to
use 2 visible text strings (not HTML comments) as the start and end
arguments.

Public Function gsGetString(rsURL As String, _
rsStartHTML As String, rsEndHTML As String) As String
Dim ie As Object
Dim sHTML As String
Dim lStartPos As Long
Dim lEndPos As Long

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Navigate rsURL
Do Until Not .Busy And .ReadyState = 4
DoEvents
Loop
sHTML = .Document.Body.InnerHTML
End With

ie.Quit
Set ie = Nothing

lStartPos = InStr(1, sHTML, rsStartHTML, vbTextCompare)
If lStartPos Then
lStartPos = lStartPos + Len(rsStartHTML)
lEndPos = InStr(lStartPos, sHTML, rsEndHTML, vbTextCompare)
If lEndPos Then
lEndPos = lEndPos - 1
gsGetString = Mid$(sHTML, lStartPos, lEndPos _
- lStartPos + 1)
End If
End If
End Function

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hi,

I am trying to perform a webquery that grabs specific data from a
page. I want to grab only the data between two specific tags
"<!--StartTag-->" and "<!--EndTag-->"

Is there any way to do this? The webquery built into excel does not
seem to allow for this kind of specific parsing. Any help would be
appreciated.

thanks,
dave
 
Back
Top