|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Python - easy question
Hello, I'm pretty new to Python and have the following question before I proceed with studying it further:
The question is about openurl function. Let's say I want my python script to access password protected page, how would I do that? Will it open IE and try to access it or does it access the page "internally". Sample code would be awesome. |
|
#2
|
||||
|
||||
|
Hi Pasha,
This rather untidy example used to work fine but with the recent update to Devsheds forums it could very well be broken ![]() Code:
#!/usr/bin/env python
import urllib, urllib2
def update(link, username, password, email, signature):
param1 = urllib.urlencode({'action': 'login', 'username': username, 'password': password})
param2 = urllib.urlencode({'action': 'updateprofile', 'email': email, 'emailconfirm': email, 'signature': signature})
cookie = urllib.urlopen(link, param1).info()['Set-Cookie']
cookie = [c for c in cookie.split() if c.endswith(';')][::2]
urllib.urlopen(urllib2.Request(link, param2, {'Cookie': ''.join(cookie)}))
update('http://forums.devshed.com/member.php', 'netytan', 'passwd', 'netytan@somewhere.com', 'www.python.org')
If you hadn't guessed it already, this script updates a users signature. But it does show how you can pass arguments to pages etc. Not for the weak heated and it usually takes some time to figure out jsut what a page needs. especially if you can't look at the source code! Mark. |
|
#3
|
||||
|
||||
|
I used this in a batch file:
Code:
import urllib
class myopener(urllib.FancyURLopener):
def prompt_user_passwd(self,host,realm):
return ("username","password")
sess = myopener()
f = sess.open("http://somewhere/index.html")
page = f.read()
just put in a valid username and password. You can of course modify prompt_user_passwd to use raw_input ![]() Grim
__________________
*** Experimental Python Markup CGI V2 *** |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python - easy question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|