You are not logged in.

#1 2009-08-08 09:09:58

augre
Member
Registered: 2009-08-08
Posts: 4

I don't find things in Python, can you help me?

First

I'd like to open a file with the operating systems associated program from python code.
Can't find a function does this sad

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 2009-08-08 12:25:11

linkmaster03
Member
Registered: 2008-12-27
Posts: 269

Re: I don't find things in Python, can you help me?

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

#3 2009-08-08 12:39:48

keenerd
Package Maintainer (PM)
Registered: 2007-02-22
Posts: 647
Website

Re: I don't find things in Python, can you help me?

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

#4 2009-08-08 14:40:36

augre
Member
Registered: 2009-08-08
Posts: 4

Re: I don't find things in Python, can you help me?

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

#5 2009-08-08 14:51:13

augre
Member
Registered: 2009-08-08
Posts: 4

Re: I don't find things in Python, can you help me?

I find that i was mistaken because mechanize resolves the user agent problem easily.(and i use mechanize:)
http://wwwsearch.sourceforge.net/mechanize/

Offline

#6 2009-08-09 10:05:57

augre
Member
Registered: 2009-08-08
Posts: 4

Re: I don't find things in Python, can you help me?

1. SOLUTION big_smile: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 big_smile:D

Offline

Board footer

Powered by FluxBB