0

How can I make my program execute only when a certain webpage is opened.? For example I want to execute my program only when I visit the webpage www.google.com. So far I made my program execute only when the given webpage is up by using the lines below, but how can I execute only when user view the page google.com?

loop_value = 1
while (loop_value == 1):
    try:
        urllib2.urlopen('http://google.com')
    except urllib2.URLError, e:
        time.sleep(10)
    else:
        loop_value = 0
        main()

Any suggestions would be appreciated. Thanks!

4
  • Do you mean you want your script to execute if you visit google.com in e.g. Chrome/Firefox? Commented Jun 3, 2014 at 17:30
  • exactly. regardless of any browser. Commented Jun 3, 2014 at 17:31
  • 1
    I'm not really sure if that's possible with Python alone. You'd either need a binding with the browser, or somehow intercept GET requests that your machine sends. Commented Jun 3, 2014 at 17:32
  • I wanted the way by which I can intercept the GET requests.. Any links to get idea, please? Commented Jun 3, 2014 at 17:36

1 Answer 1

1

Just python cannot directly see what webpages are being accessed unless the user goes through urllib2 or something of the likes.


Instead, try accessing it with an overlay of JavaScript or something of the likes, and then you can trigger your python script with that.

Or, as @pbackup said,

You can set up transparent proxy to intercept the traffic

Sign up to request clarification or add additional context in comments.

6 Comments

Unless he had it sit in the background and check all the processes. Even then it would be reliant on how the processes are displayed and I'm pretty sure the browsers don't list what webpages they are visiting from a ps perspective.
You can set up transparent proxy to intercept the traffic.
@pbackup will add that
But the transparent proxy will only work for http://google.com, not https://google.com.
Intercepting the traffic by setting up transparent proxy is what I needed. Thanks for the suggestions.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.