Post by metro on Apr 26, 2017 5:56:31 GMT -5
Hi all
I'm looking for a way to copy the contents on an iframe to a variable programmatically
I have been Successfully using a program to scrape a website for stock market quotes for the past few years and
only for personal use , this has come to a screaming halt in the last week as the site seems to either block my attempts
or uses another method of displaying the table data that is not accessible via httpget
I have managed to get around this by using an iframe to display the required data page within my RB program and then right click to copy and the paste
the contents into a textarea. stripping out the info I require is quite easy.
I then deal with the results in my calculations.
I would like to automate this.
I have read of ways to do it with javascript however its a little out of my league at the moment.
any help appreciated.
cut down code:
I'm looking for a way to copy the contents on an iframe to a variable programmatically
I have been Successfully using a program to scrape a website for stock market quotes for the past few years and
only for personal use , this has come to a screaming halt in the last week as the site seems to either block my attempts
or uses another method of displaying the table data that is not accessible via httpget
I have managed to get around this by using an iframe to display the required data page within my RB program and then right click to copy and the paste
the contents into a textarea. stripping out the info I require is quite easy.
I then deal with the results in my calculations.
I would like to automate this.
I have read of ways to do it with javascript however its a little out of my league at the moment.
any help appreciated.
cut down code:
global data2save$
dim Opt$(1000): Year$="2017" : asxcode$="xjo" : Month$="Jun"
'print DefaultDir$ + "/public/test.txt"
'create a button with sub event handler
'goto [skip]
button #doStuff, "Paste data then press Button ", [savethefile]
print:print
html"<left>"
textarea #t, "",185,10
url2find$="http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode="+asxcode$+"&expiryDate="+Month$+"+"+Year$+"&optionType=B"
print url2find$
''html "<div id='IFR' ALIGN=CENTER><IFRAME SRC="+url2find$+" WIDTH=600 HEIGHT=400 ></div>"
'html "<div id='IFR' ALIGN=RIGHT><IFRAME SRC='"+url2find$+"' WIDTH=200 HEIGHT=800 ></IFRAME></div>"
html"<iframe src="+url2find$+" width=80% height=600 align=left></IFRAME>"
#t setfocus()
print
wait
[savethefile]
data2save$ = #t contents$()
call tableselect
#t text("")
CLS
'textarea #t2, data2save$,200,30
'print #t , data2save$
open DefaultDir$ + "/public/test.txt" for output as #f
data2save$= strRep$(data2save$,",","")
print #f, data2save$
close #f
[skip]
Call setCSS
OPEN DefaultDir$ + "/public/test.txt" for input as #f
z=1
WHILE eof(#f)=0
line input #f, Opt$
' need to load up the file into an array
' then insert the comma between field after
if Opt$ <> "" then
token$ = "?"
for index = 1 to 10
token$ = word$(Opt$, index)
newline$=newline$+","+token$
Opt$(z)=newline$
next
' print Opt$(z)
z=z+1
end if
newline$=""
WEND
close #f
for z = 3 to z-1
length= LEN(Opt$(z))
Opt$(z)= RIGHT$(Opt$(z),length-1)
length= LEN(Opt$(z))
if right$(Opt$(z),1)="," then
Opt$(z)=LEFT$(Opt$(z),length-1)
if RIGHT$(Opt$(z),5)=",,,,," then
Opt$(z)=Opt$(z)+","
end if
end if
'Opt$(z)= Chr$(34)+Opt$(z)+Chr$(34)
Opt$(z)= strRep$(Opt$(z),",",";")
'print Opt$(z)
next
DIM tabledat$(11,z+20): dim token$(11) 'unsure why I need the extra 20
' SORTED THE ZERO BASE for tabledat$(x,x)
' so the link's would work
for column =1 to 10
for z= 3 to z+2
item$ =word$(Opt$(z), column, ";")
tabledat$(column-1, z-3) =item$ ' to avoid taking in the first 3 lines (header)
next z
next column
' TABLE HEADER
html"<center>"
div mytable
table #mytable,tabledat$()
html "<table align = center border=1>"
#mytable columnnames("Code,Expirydate,P/C,Exercise,Bid,Offer,Last,Volume,Openinterest,MarginPrice")
#mytable link("Code", "[order]")
#mytable caption("POTENTIAL TRADES")
cssclass "table", "{ border: 3px ridge #DDF ; border-spacing: 4px }"
html "</table>"
render #mytable
end div
wait
[order]
print "You selected "; EventKey$
wait
wait
sub tableselect
data2save$= upto$(data2save$,"An *")
data2save$= after$(data2save$,"Code Expiry")
end sub
function after$(source$, match$)
i = instr(source$, match$)
if i then after$ = mid$(source$,i+len(match$))
end function
function upto$(source$, match$)
i = instr(source$, match$)
if i then upto$=left$(source$,i-1) else upto$=source$
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
Sub setCSS
CSSID #Container, "{
align center
margin-left: auto;
margin-right: auto;
width: 70%;
Margin: 20px Auto;
Background-Color: #C6C6B8;
Font-Family: Tahoma;
Font-Size: 1em;
Font-Weight: Bold;
Text-Align: Center;
Color: Black;
Width: 1000px;
Height: 710px;
Padding: 20px 20px 0px 10px;
Border-Color: #45453D;
Border-Size: Thick;
Border-Style: Ridge;
Border-Bottom-Style: Ridge;
}"
cssid #navigation, "{
font-family: Tahoma;
font-size: small;
color: #CC0000;
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;
}"
'********************************************************
CSSID #footer, "{
Background-Color:#77776E;
Font-Family: Verdana;
Width: 999px;
Height: 25px;
Padding: 5px 5px 5px 0px;
Text-Align: Center;
}"
CSSID #mytable, "{
align center
border: 3px ridge #DDF ;
border-spacing: 4px
Font-Family: Verdana;
Font-Size: .9em;
Padding: 10px 10px 0px 0px;
Width: 800px;
Height: 570px;
overflow-y: scroll;
}"
cssclass "tr", "{ background: #CCF }"
CSSID #h1, "{
font-family: Tahoma;
display: block;
font-family: Tahoma;
color: #3D3D1F;
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}"
End Sub