HTTPGET Table data

new BookmarkLockedFalling
metro
Full Member
***

metro Avatar

Posts: 207

Post by metro on Sept 23, 2015 23:19:32 GMT -5

After hours of head scratching I'm reluctantly asking for help again
I can download data to a file using the code below but if I try for a second file
its always empty.

Tip: choose a month one month later than the current month
to avoid expired dates

any help appreciated... the code here is a cut down version

EDIT: tblBeg is 0 (zero) the second time through, I think that's the issue
I don't understand why as it should reset to the next instr(lowData,ドル"<table",tblEnd)
as lowData$ is changed

' -------------------------------------
' HTML <table> data to CSC file
' converts all tables in the html
' change: webPage$ and fileName$ belohtml " w
' --------------------------------------

DIM asx$(58)

sep$=Chr$(34)+Chr$(44)+Chr$(34)
DIM a$(1000):dim dat$(1000): DIM tabledat$(11,1500)
Dim row$(10000): dim yrs$(3)
global DR,ドルChartCode$

'LOAD ASX CODES
AsxOptCodesList$ = "---,AGL,AIO,AMC,AMP,ANZ,ASX,AWC,BEN,BHP,BLD,BOQ,BSL,BXB,CBA,CCL,CIM,COH,CPU,CSL,CSR,FMG,FXJ,GPT,HVN,IAG,"
AsxOptCodesList$ = AsxOptCodesList$ + "AJHX,LLC,MQA,MQG,MYR,NAB,NCM,ORG,ORI,OSH,OZL,PPX,QAN,QBE,RIO,SGP,STO,STW,SUN,TAH,"
AsxOptCodesList$ = AsxOptCodesList$ + "TCL,TEN,TLS,TOL,TTS,WBC,WDC,WES,WOR,WOW,WPL,XJO"
for a=1 to 58
asx$(a)=WORD$(AsxOptCodesList,ドルa,",")
next a

' SET UP MONTHS
dim array6$(15) 'not coded for "All" months yet
sentence$ = "January February March April May June July August September October November December All"
token$ = "?" : index=1
while token$ <> ""
token$ = word$(sentence,ドル index)
array6$(index)= left$(token,3ドル)
index = index + 1
wend



' SETUP YEARS
yrs$(1)="2015"
yrs$(2)="2016"
yrs$(3)="2017"


'ZERO VARIABLES
selected$=""

'SET MONTH IN LISTBOX
idx=10 :array6$(0)= array6$(idx)

' change this to your output csv file name


' NEED TO SET YEAR FROM DATE$
' NEED to set month FROM date$
' NEED TO SETUP GETHTTP

'*************************begin***********

Call setCSS

[MAINLINE]
gosub [displaynav]
WAIT

[GETDATA]

'SET INPUTS
selmonth$=#mnth selection$() : selyear$=#ayear selection$() : asxcode$=#lb selection$()

' change this to your web page
webPage$ = "http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode="+asxcode$+"&expiryDate="+ selmonth$ + "+" +selyear$ +"&optionType=B"
print webPage$

' change this to your output csv file name
fileName$ = asxcode$

htmlData$ = httpget$(webPage$)

lowData$ = lower$(htmlData$)
open DefaultDir$ + "\public\";fileName$;".csv" for output as #f

[nxtTbl]
tblBeg = instr(lowData,ドル"<table",tblEnd)
if tblBeg = 0 then goto [endTbl]instr(lowData,ドル"<table",tblEnd)
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)
print #f, """";left$(lineData,ドルlen(lineData$) -2)


lineBeg = lineEnd + 1
lineEnd = instr(tblData,ドル"</tr>",lineBeg)
wend
'print "----------------- end <table> --------------------------"
print #f, ""
goto [nxtTbl]

[endTbl]
close #f
WAIT

[displaynav]
div navigation
print "Menu"
print
print
print "enter year & month"

listbox #ayear,yrs$(),1
#ayear select(selyear$)

print

listbox #mnth,array6$(),1
#mnth select(selmonth$)
print
print "enter ASX code"

listbox #lb,asx$(),1
#lb select(asxcode$)
print
link #testIt, "Download Data", [GETDATA]

#testIt CSSClass("fancyButton")

end div
RETURN

' ---------------------------------.--------
' 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

' --------------------------------
' string replace rep str with
' --------------------------------
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

' --------------------------------
' 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
Sub setCSS

cssid #navigation, "{

font-family: Tahoma;
font-size: small;
color: #6B6B47;
border-right: 3px solid #666666;
background: #ADAD99;
padding: 4px;
width: 250px;
height: 570px;
float: left;
white-space: normal;
background-repeat: repeat;
background-image: url('/pagebg.PNG');
Text-Align: Center;
}"
'********************************************************




'more styles added
CSSClass "a.fancyButton", "{
align center;
Text-Decoration: None;
Font-Size: 14pt;
Font-Weight: Bold;
Width: 240px;
Height: 30px;
Display: Block;
Background: #C0C0C00;
Color: #000000;
Text-Align: Center;
Border-Width: Thick;
Border-Style: Outset;
Border-Color: #AAAAAA;
}"
End Sub
Last Edit: Sept 24, 2015 0:13:00 GMT -5 by metro
Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate
neal
Full Member
***

neal Avatar

Posts: 104

metro
Full Member
***

metro Avatar

Posts: 207

Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate