-1

Is there a way to know the total time one spends on a page opened in a browser using a python script? For example if one uses gmail, and is currently using it (i.e the page is non idle) can we know the total time for which the page was active? Further explaining what I intend to do:

  1. By active means I am actually using the page, be it reading it, doing some typing or doing some mouse work.
  2. It would be great if there would somehow be a way to exclude the time spent in breaks, perhaps introduce some error? I am not sure whether javascript would be apt for it, and am open to suggestions!
mjnovice
  • 172
  • 11
  • Do you mean on a server running Python, or Python installed on the user's local machine? When you say "currently using" (active) do you mean just clicking, or sending information back to the host server? Also, do you want to exclude breaks (when they were using a page, had a coffee (or went on holiday), but came back to the opened page)? – Andy Hayden Sep 21 '12 at 09:09
  • Now you know Python it's but a short step to other programming languages, like Javascript which runs on the client browser and would be more suited to your problem. – Paul Collingwood Sep 21 '12 at 09:11
  • @AndyHayden I meant, Python installed on user's local machine. Currently using means that the webpage is the active page/tab in my web browser and the browser of course is not minimized! – mjnovice Jul 06 '13 at 14:53
  • @PaulC I totally agree with you and think that javascript would be apt for it and hence have modified the question. – mjnovice Jul 06 '13 at 14:54

3 Answers3

1

Short answer: I don't think so.

This isn't really an issue of whether Python can do it, it's to do with whether your browser exposes that information in a way that an external program/script can query.

There's also the issue of how you define/determine which page is "active". Is it sufficient that the browser window is currently the active window and the page is on the selected tab? Or would you expect some kind of interaction? What if I'm reading a long text and so am not making interacting with the page for a period of time, does that still count as active?

The fact that it's hard to detect activity even from the website point of view, doing so from a 3rd party application/script be it written in Python or any other language would be even trickier.

If you wish to explore this further, I'd say your best bet would be to write a browser extension/plugin. In fact, there may already be existing ones that may meet your needs.

Community
  • 1
  • 1
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
  • @Shwan, thanks for an elaborate answer! I have updated the question, explaining what I exactly wish to achieve. Sadly, the links to the **existing ones** you posted is not available to firefox 21.0 . If writing these extensions is not hard enough, I would surely like to know how can we write/update the extensions in the link! – mjnovice Jul 06 '13 at 15:05
0

That sounds highly browser and platform-specific.

So, in general "no".

If the browser has some kind of interface or "hook" support then it might be possible.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

This isn't really Python specific.

The best I can come up with is leave something like "Google Analytics" to do all that sort of stuff for you, then using your choice of language, get the data you need from the API

Of course that might not be appropriate, and the rules for how long it deems the page viewed, etc... may not work, but at least it'll be consistent.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280