Posts: 100
Threads: 45
Joined: Jan 2014
Guys,
How can i copy a table in javascript?
I tried the code below but it's not working =(
Macro
Macro33
out
HtmlDoc d
;g1
d.InitFromWeb("https://datatables.net/examples/data_sources/js_array.html")
rep 10 ;;wait for the javascript to finish
,1
,str s=d.GetHtml("table" "example")
,1
,err out "waiting"; continue
,break
if(!s.len)
,out "RETRY"
,goto g1
out s
Help!
Posts: 12,097
Threads: 142
Joined: Dec 2002
Need d.SetOptions(2).
Macro
Macro2767
out
HtmlDoc d
d.SetOptions(2)
;g1
d.InitFromWeb("https://datatables.net/examples/data_sources/js_array.html")
rep 10 ;;wait for the javascript to finish
,1
,str s=d.GetHtml("table" "example")
,if(s.len) break
,out "waiting"
if(!s.len)
,out "RETRY"
,goto g1
out s
Posts: 100
Threads: 45
Joined: Jan 2014
Thanks.
Just one crucial point. Could you pls tell me why the same code doesnt work in the example below:
Macro
Macro33
out
HtmlDoc d
d.SetOptions(2)
;g1
d.InitFromWeb("http://www.imea.com.br/imea-site/indicador-milho")
rep 10 ;;wait for the javascript to finish
,1
,str s=d.GetHtml("tbody" "body-milho-disponivel")
,if(s.len) break
,out "waiting"
if(!s.len)
,out "RETRY"
,goto g1
out s
Posts: 12,097
Threads: 142
Joined: Dec 2002
Here works. After maybe 10 seconds shows
<tbody id="body-milho-disponivel">
<tr>
...
...
Posts: 100
Threads: 45
Joined: Jan 2014
It returns a empty table, since the code its not waiting or considering the java load.
The full table, which you can see in the website, it is :
<tbody id="body-milho-disponivel">
<tr class="">
<td>
<small> Indicador MT </small>
</td>
<td class="text-item-box">
<small> 23,49 </small>
</td>
<td class="text-item-box">
<small> <span class="txt-venda blue">1,29</span> </small>
</td>
</tr>
<tr class="">
<td>
<small> Alto Araguaia </small>
</td>
<td class="text-item-box">
<small> 26,85 </small>
</td>
Posts: 12,097
Threads: 142
Joined: Dec 2002
Unstable. The first time it retrieved whole filled table. Then either empty table (335 length) or did not work.
Then I tried with a visible WebBrowser control in a dialog. At first did not work. Now works. Don't know why.
Then also tried the script, and it did not work, but after adding opt waitmsg 1 now it works.
Macro
Macro2753
opt waitmsg 1
int minLength=500
HtmlDoc d
d.SetOptions(2)
;g1
d.InitFromWeb("http://www.imea.com.br/imea-site/indicador-milho")
rep 10 ;;wait for the javascript to finish
,1
,str s=d.GetHtml("tbody" "body-milho-disponivel")
,out s.len ;;335 when empty, 5308 when full
,if(s.len>=minLength) break
,out "waiting"
if(s.len<minLength)
,out "RETRY"
,goto g1
out s
Function
Dialog204
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 754 404 "Dialog"
;3 ActiveX 0x54030000 0x0 0 16 754 388 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;4 Button 0x54032000 0x0 0 0 50 14 "QM forum"
;5 Button 0x54032000 0x0 56 0 48 14 "IMEA"
;END DIALOG
;DIALOG EDITOR: "" 0x2040400 "*" "" "" ""
str controls = "3"
str ax3SHD
ax3SHD="http://www.imea.com.br/imea-site/indicador-milho"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
SHDocVw.WebBrowser we3
we3._getcontrol(id(3 hDlg))
sel wParam
,case 4
,we3.Navigate("http://www.quickmacros.com/forum")
,case 5
,we3.Navigate("http://www.imea.com.br/imea-site/indicador-milho")
ret 1
Posts: 100
Threads: 45
Joined: Jan 2014
Thank you very much! I Learned a lot!