Post by metro on Mar 31, 2018 5:07:33 GMT -5
I use this code to get Options data from the Australian Stock Exchange
Lots of data so a bit slow..
Thanks to meerkat ( for the functions) a member here and @runbasic.proboards
Lots of data so a bit slow..
Thanks to meerkat ( for the functions) a member here and @runbasic.proboards
asxcode$="NAB" ' AUSTRALIAN STOCK MARKET NATIONAL BANK CODE (TICKER)
call Table2CSV asxcode$
WAIT
SUB Table2CSV asxcode$
'
webPage$="https://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode="+asxcode$+"&expiryDate=&optionType=B"
fileName$ = asxcode$
htmlData$ = httpget$(webPage$)
lowData$ = lower$(htmlData$)
' change this to your output csv file name
'open DefaultDir$+"\"+"DATA\"+ fileName$+".dat" for output as #f
[nxtTbl]
tblBeg = instr(lowData$,"<table",tblEnd)
if tblBeg = 0 then goto [endTbl]
tblEnd = instr(lowData$,"</table>",tblBeg)
tblData$ = mid$(htmlData$,tblBeg,(tblEnd - tblBeg) + 8)
lineBeg = 0
lineEnd = instr(tblData$,"</tr>",lineBeg)
while lineEnd > 0
lineData$ = mid$(tblData$,lineBeg - 1,(lineEnd - lineBeg) + 1)
lineData$ = strip$(lineData$)
lineData$ = strRep$(lineData$,"</td>",",")
lineData$ = strRep$(lineData$,"</th>",",")
lineData$ = tags$(lineData$,"")
lineData$ = strRep$(lineData$," "," ")
lineData$ = strRep$(lineData$,"&","and")
print "";left$(lineData$,len(lineData$) -2)
' OR SAVE TO FILE
' print #f, "";left$(lineData$,len(lineData$) -2)
lineBeg = lineEnd + 1
lineEnd = instr(tblData$,"</tr>",lineBeg)
wend
'print "----------------- end <table> --------------------------"
goto [nxtTbl]
[endTbl]
'close #f
END SUB
' --------------------------------
' Replace HTML <tags> with$
' --------------------------------
FUNCTION tags$(tag$,with$)
i = instr(tag$,"<")
j = instr(tag$,">",i)
WHILE j > i
tag$ = left$(tag$,i - 1) + mid$(tag$,j + 1)
i = instr(tag$,"<")
j = instr(tag$,">")
WEND
tags$ = tag$
END FUNCTION
' -----------------------------------------
' strip junk
' -----------------------------------------
FUNCTION strip$(str$)
strip$ = ""
for i = 1 to len(str$)
a$ = MID$(str$,i,1)
a = ASC(a$)
if a > 31 then
if a < 127 then
if a$ <> "'" then
if a$ <> "" then
strip$ = strip$ + a$
end if
end if
end if
end if
next i
END FUNCTION
FUNCTION strRep$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
strRep$ = strRep$ + with$
i = i + ln1
else
strRep$ = strRep$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION