Help-log in to a web page
Hi all,
I'm a newbie to python.I need to login to a webpage after supplying
usename and password.
import urllib
sock = urllib.urlopen("http://xop-pc.main.com";)
htmlSource = sock.read()
sock.close()
print htmlSource
In the above code how can i supply username and password to that URL.
Thanks for you time.
Thanks
Amen.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help-log in to a web page
Laszlo Zsolt Nagy wrote:
Murugesh wrote:
Hi all,
I'm a newbie to python.I need to login to a webpage after supplying
usename and password.
import urllib sock = urllib.urlopen("http://xop-pc.main.com")
htmlSource = sock.read()
sock.close() print
htmlSource
In the above code how can i supply username and password to that URL.
Thanks for you time.
xop-pc.main.com is not an existing site.
Can you tell me what kind of authentication method it is using?
If that is the "basic authentication" (defined the standard HTTP
protocol) then you need to read this:
http://docs.python.org/lib/urlopener-objs.html
Basically, you need to subclass URLopener or FancyURLopener, and
overwrite its "prompt_user_passwd" method.
That method will be then called whenever the server needs
authentication.
Here is a template for you (untested):
from urllib import FancyURLOpener
class MyOpener(FancyURLOpener):
def prompt_user_passwd(host,realm):
return ('myusername','mypassword')
opener = MyOpener({})
f = opener.open("http://xop-pc.main.com")
try:
html_source = f.read()
finally:
f.close()
Best,
Les
I tried to view the source,it has,
src=""
height="80">* User Name
pan>
id="username" class="x4" name="j_username" size="30"
type="text"
value="myadmin">
class="xc">* Password
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help-log in to a web page
Murugesh wrote:
Laszlo Zsolt Nagy wrote:
Murugesh wrote:
Hi all,
I'm a newbie to python.I need to login to a webpage after supplying
usename and password.
import urllib sock = urllib.urlopen("http://xop-pc.main.com")
htmlSource = sock.read()
sock.close() print
htmlSource
In the above code how can i supply username and password to that URL.
Thanks for you time.
xop-pc.main.com is not an existing site.
Can you tell me what kind of authentication method it is using?
If that is the "basic authentication" (defined the standard HTTP
protocol) then you need to read this:
http://docs.python.org/lib/urlopener-objs.html
Basically, you need to subclass URLopener or FancyURLopener, and
overwrite its "prompt_user_passwd" method.
That method will be then called whenever the server needs
authentication.
Here is a template for you (untested):
from urllib import FancyURLOpener
class MyOpener(FancyURLOpener):
def prompt_user_passwd(host,realm):
return ('myusername','mypassword')
opener = MyOpener({})
f = opener.open("http://xop-pc.main.com")
try:
html_source = f.read()
finally:
f.close()
Best,
Les
I tried to view the source,it has,
src=""
height="80">* User Name
pan>
id="username" class="x4" name="j_username" size="30"
type="text"
value="myadmin">
class="xc">* Password
>
Les,
I tried your code and it hangs.I believe the authentication is
different from the standard one.
Any help will be appreciated.
Thanks
Amen
--
http://mail.python.org/mailman/listinfo/python-list
to automate an interactive shell
Hi all, I'm a newbie and would like to how python is efficient in automating an interative shell(I have a CLI executable which interatcs with the user). Any starters would be greatly appreciated. Thanks, Murugesh -- http://mail.python.org/mailman/listinfo/python-list
