in reply to Fast efficient webpage section monitoring

Evening to you all.

Just to give this thread a bit of a conclusion: I think indeed that the right way to go is to look at the AJAX, that is definitely the only way to get out of reloading the page. I have been digging into the code, and it does indeed contain a lot of XMLHttpRequest calls.

As to the best way to implement watching of this particular page, the key - I humbly think - lies in the fact that the page watches itself, and that it - probably - does it in a rather reliable way. So the code in the end should just look something like:

use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new(); $mech->autoclose_tab( 0 ); $mech->get("$URL"); while (1) { $mech->events( "document.database_changed_function()" ); #not got this part working yet... };

I agree that one interesting avenue would have been Selenium, and I now remember that at the very onset of all this, before I figured out that the "button" was a simple POST request hidden under a thousand layers of Javascript, I had looked a Selenium for its "imitation" capability (script what you do). Never went too far down that avenue though.

What I am confronted with now is the sheer complexity of the JS in this page. I am having a million issues with scope and such whenever I try to get Mechanize::Firefox to interact with the page. It's written using angularjs.org which in and of itself is super cool, but insanely complex as far as the JS goes (no doubt the JS gurus would contradict me there but hey, I'm not a javascript guy!)

So here I am, trying to figure out which function is supposed to keep a watch on the database of translations, and what scope all this is happening in...

Maybe I'll figure it out (preferably before the site migrates to Angular 2 and the whole thing changes, haha), maybe not, but in any case I'm learning a lot of JS, and perl too for that matter, the Mech::FF module is quite instructive.

Once again thanks for your help and for hearing me out. Appreciate all the kind comments.

Will be back soon with some more questions no doubt.

All the best to you all,
Regards, Mark.

Replies are listed 'Best First'.
Re^2: Fast efficient webpage section monitoring
by GrandFather (Saint) on Apr 06, 2016 at 02:49 UTC

    There may be no "public" or named function that does the job. A very common idiom in JavaScript land is to use nested anonymous functions to get work done. What you are looking for may be an anonymous function in a nested chain hooked to an event and essentially impossible to get at from outside.

    Premature optimization is the root of all job security
      Now that would make a lot of sense... I see lines and lines of nested functions, and can't seem to figure out when the call to the one containing the XMLHttprequest is actually made! I really have some javascript brushing up to do! Thanks for the tip :)