Browser Widget Timing
Posted: Fri Feb 19, 2021 7:52 pm
I want to use the Browser Widget to retrieve data from a collection of similar but different web pages. I want to get the data quickly and reliably. The URLs are contained in the field "URLS". The following code (abbreviated) seems to work.
The pause between setting the URL for the widget and getting the htmltext is necessary to give the widget time to finish the retrieval from the web page. I know that if I cut the wait to say 10 ticks that the retrieve will not be complete and some if the data I want will not be supplied. I suppose, depending in the web traffic. that my wait of 60 ticks may not be enough on some occasions.
Since I would like to have the retrievals of data be as close as possible (i.e. No wasted ticks) I tried a different approach. I have created a custom variable in the widget called cBusy and made some code modifications to now look like the following.
I added this code to the browser widget:
My mouseUp code was changed to this;
This executes but only gives me the data for the last website. If I change the wait from 5 ticks to 60 ticks it does work. I put break points in the widgets code at the two places where I have "set the cBusy of me to" and, interestingly enough, in the 60 tick version I has all my answers before any stop. When It finally did break it was at "browserNavigateBegin".
Any ideas?
Thanks,
Larry
Code: Select all
on mouseUp pMouseButton
repeat for each line tUrl in field "URLS"
set the url of widget "Browser" to tUrl
wait 60 ticks
put the htmltext of widget "Browser" into tText
--parse tText to get the data I want
end repeat
end mouseUp
Since I would like to have the retrievals of data be as close as possible (i.e. No wasted ticks) I tried a different approach. I have created a custom variable in the widget called cBusy and made some code modifications to now look like the following.
I added this code to the browser widget:
Code: Select all
on browserNavigateBegin pUrl
set the cBusy of me to true
end browserNavigateBegin
on browserNavigateComplete pUrl
set the cBusy of me to false
end browserNavigateComplete
Code: Select all
on mouseUp pMouseButton
repeat for each line tUrl in field "URLS"
if tUrl="ALL" then next repeat
set the cBusy of widget "Browser" to false
set the url of widget "Browser" to tUrl
repeat
wait 5 ticks
put the cBusy of widget "Browser" into tFlag
if tFlag is false then exit repeat
end repeat
put the htmltext of widget "Browser" into tText
--parse the text to get the data I want
end repeat
end mouseUp
Any ideas?
Thanks,
Larry