6 Replies Latest reply on Mar 9, 2015 3:11 PM by Benjamin Fehr

    How to tell when webview has finished loading?

    mark_b

      Hi All,

      I am using scripts to scrape a website (Amazon) for specific book information.  It works fine, as long as I walk through the debugger.  But when I run the script without the debugger, the page hasn't finished loading when the script hits the GetLayoutObjectAttribute ( "AmazonSearch"; "content" ).  Is there a way to tell how much of a pause is needed to wait for the webviewer?

      Cheers, Mark

        • 1. Re: How to tell when webview has finished loading?
          Mike Duncan

          What I typically do is to test for a pattern count looking for "</html>" to try to detect if at least that much of the html has been received. You will probably want to loop, pause for a second or so, then perform this test. I would recommend putting in a default timeout for this as well, so you don't get stuck waiting for a page that never loads. You can do that by incrementing a variable in your loop, and exit if it gets beyond a certain amount.

           

          Hope this helps.

          Mike

          • 2. Re: How to tell when webview has finished loading?
            wimdecorte

            Put your script in a loop that checks for the HTML closing tag </HTML>, pause for something like 0.25 seconds each iteration

            • 3. Re: How to tell when webview has finished loading?
              mark_b

              Thanks Wim and Mike,

              While you guys were posting your answers, I came up with the a similar solution, except in Amazon, the </HTML> tag shows up all over the place (12 times on one page).  So I used the </BODY></HTML> tags.  That worked.

              Thanks again.

              Mark

              • 4. Re: How to tell when webview has finished loading?
                Benjamin Fehr

                as far as I know, the MBS PlugIn can detect if web viewer has finished loading.

                You could also split task by GetLayoutObjectAttribute ( "AmazonSearch"; "source" )

                in order to get current href, which you then can use for 'GetFromURL'.

                Chances are that that "source" get's loaded faster and more reliable.

                 

                Even with "source", you should follow up Mike Duncanrecommendation with a loop and a counter.

                I set    Vars = $start; Get(SystemTimeUTCMilliseconds) + 5000     before the loop

                and     End Loop if Get(SystemTimeUTCMilliseconds) > $start

                • 5. Re: How to tell when webview has finished loading?
                  beverly

                  On Mar 9, 2015, at 4:15 PM, Mike Duncan <noreply@filemaker.com> wrote

                   

                  What I typically do is to test for a pattern count looking for "</html>" to try to detect if at least that much of the html has been received. You will probably want to loop, pause for a second or so, then perform this test. I would recommend putting in a default timeout for this as well, so you don't get stuck waiting for a page that never loads. You can do that by incrementing a variable in your loop, and exit if it gets beyond a certain amount.

                   

                  I heard from somewhere that the final "</html>" may not appear. I believe that "</body>" was listed as a better test.  Hopefully the web designer did not forget these end tag(s). Tho, modern browsers often allow such to be "implied" without actually being in the code, so YMMV!

                   

                  Beverly

                  • 6. Re: How to tell when webview has finished loading?
                    Benjamin Fehr

                    Great point!

                    … and so simple. Assuming that rendering is similar to XML-Parsing by going from top/left to bottom/right AND closing tag </html> is part of every website, this should work perfect.

                     

                    Damn'! I thin I have to rebuild a couple of scripts tonight