You are not logged in.
First
I'd like to open a file with the operating systems associated program from python code.
Can't find a function does this
2.
My program logs in to websites but there is a site that doesn't leave enter because it asks the type of the browser and user agents.
So this site does this because it doesn't want to leave enter bots, just browsers.
How can i send these values to appear a browser?
Anyone ideas?
these are the most important
thank you!
Offline
2. You can set the user-agent when using urllib2 like so:
import urllib2
web = urllib2.build_opener()
AGENT = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090804 Firefox/3.5.2'
web.addheaders = [('User-agent', AGENT)]
web.open('http://whatsmyuseragent.com/')
Last edited by linkmaster03 (2009-08-08 12:25:44)
Offline
Welcome to the forums.
1. If there is such a function, it will be in a library specific to your desktop environment. For example, the "gnome-python" library. There probably won't be a function for that in stock Python. What you can do is find the application responsible for opening documents. For example in Gnome (though I don't use Gnome), I hear it is called "exo". So,
subprocess.Popen("exo %s" % document_path)
would do the trick.
Offline
Thank you the fast reponses!
keenerd don't you know a trick like this under windows?
i will try your solution now, but i need it under windows too.
Offline
I find that i was mistaken because mechanize resolves the user agent problem easily.(and i use mechanize:)
http://wwwsearch.sourceforge.net/mechanize/
Offline
1. SOLUTION :D
webbrowser.open(url[, new=0[, autoraise=1]])
Note that on some platforms, trying to open a filename using this function, may work and start the operating system's associated program. However, this is neither supported nor portable.
i have searched this function for a month :D
Offline