![]() |
Web Query
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 |
Web Query
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] Daveed wrote: 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 |
Web Query
Thanks,
that is precisely what i was looking for!!! Dave "Jake Marx" wrote in message ... 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] Daveed wrote: 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 |
All times are GMT +1. The time now is 10:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com