WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Data From a Webpage


Question:

I want to pick up fund price from website which does not have any log in.

http://quote.bloomberg.com/apps/quote?ticker=pbcp

I am looking for the price of 'pbcp'

Answer:


; Winbatch 2004F and MSIE 5...

#DefineSubRoutine startMSIE(url)
   Browser = ObjectOpen("InternetExplorer.Application")
   Browser.addressbar = @FALSE
   Browser.statusbar = @FALSE
   Browser.menubar = @FALSE
   Browser.toolbar = @FALSE
   browser.visible = @TRUE
   browser.navigate(url)
   ; wait until page loads...
   WaitForPageLoad()
   ; setup the document object...
   BrowserDoc = Browser.Document
   BrowserBody = BrowserDoc.Body 
   all = browserdoc.all
   Return(browser)
#EndSubRoutine

#DefineSubroutine WaitForPageLoad()  ; assume Browser
   While browser.busy || browser.readystate == 1
      TimeDelay(0.5)
   EndWhile
   While browser.Document.ReadyState != "complete"
      TimeDelay(0.5)
   EndWhile
   return
#EndSubroutine





url = "http://quote.bloomberg.com/apps/quote?ticker=pbcp"

br = startMSIE(url)

DaPrice = "Unknown"
PriceFound = @FALSE

TablesCollection = browserdoc.GetElementsByTagName("TABLE")
For x = 26 To 26    ;   bloomberg keeps the price info in the 27th table (26th for zero-based subscript)
   ThisTable = TablesCollection.item(x)
   CellsCollection = ThisTable.GetElementsByTagName("TD")
   For y = 0 To CellsCollection.length-1
      ThisCell = CellsCollection.item(y)
            SpanCollection = ThisCell.GetElementsByTagName("SPAN")
            If SpanCollection
               For z = 0 To SpanCollection.length-1 ;;
                  ThisSpan = SpanCollection.item(z)
                  If StrIndex(ThisSpan.innerText, "Price", 1, @FWDSCAN) ;<-- what we're looking for...
                     PriceValueSpan = SpanCollection.item(z+1)            ;<-- price is in the next span...
							PriceFound = @TRUE
                     DaPrice = PriceValueSpan.innerText
                     ObjectClose(PriceValueSpan)
                  EndIf
                  ObjectClose(ThisSpan)
               Next
               ObjectClose(SpanCollection)
            EndIf
      ObjectClose(ThisCell)
      If PriceFound Then Break
   Next
   ObjectClose(ThisTable)
   If PriceFound Then Break
Next

Message("Debug", DaPrice)

Exit

Article ID:   W16634
File Created: 2005:02:18:12:21:42
Last Updated: 2005:02:18:12:21:42