Hi ppl,,,,how r ya...hope u r fine..
Just have a lil problem with my program.
Im studying civil engineering . And i have problem with my registrations
So my friend creatred a program for me ,,but there is something missing in it
The main job for this program is to go to my university's site,puttin my ID and password then hit "submit" then sign up for materials....
The problem here is i feel like something missing in my friend program wich is "how to hit submit after putting mu ID and password"
so here is the site for my uni
http://portal.hu.edu.jo:7777/huregister/
and here is the code

# -*- coding: cp1256 -*-
import urllib
import httplib2
global http
import sys
from smtplib import SMTP
import datetime

print "This progrme was made for //darknessamman\\"
print
made = raw_input("Enter material no.: ")
sec = raw_input("Enter material section: ")
sec3 = raw_input("Enter material section for practice (default zero): ")
user = raw_input("Enter user number: ")
passo = raw_input("Enter user pass: ")

http= httplib2.Http()

smtp.quit()



def blue():
        url = 'http://reg3.hu.edu.jo/huregister/'
        body = {'user':user, 'pswd': passo}
        global headers
        headers = {'Content-type': 'application/x-www-form-urlencoded'}
        response,content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
        print response
        headers = {'Content-type': 'application/x-www-form-urlencoded','Cookie': response['set-cookie']}

blue()
x=0
y=0
while True:
    y=y+1
    body = {'mst_no':user, 'theory_no':sec3 , 'sec_no': sec, 'crs_no': made}
    url = 'http://reg3.hu.edu.jo/huregister/'
    response,content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
    x=x+1
    print
    print "Try number (",y,")"
    print
    print "=> blue it <="
    if x == 30 :
        blue()
        x=0
stop

any body can help ?
p.s : please just forgive me if this is not the right placer for my topic,,,coz its the 1st one !

The body variable should have a third entry that looks something like:

body = {'user':user, 'pswd': passo, 'submit':'Submit'}

or something like that. You will need to find it in the source of the page you want to log into.

Thank you man. Now i looked at the page source page and i found :

tr>
<td colspan="2" width="71" height="17"><input type="image" name="submit" img src="images/login_25.gif"></td>
<td><img src="images/login_26.gif" width="4" height="17" alt=""></td>
<td colspan="5" width="70" height="17">
<input type="image" name="reset" img src="images/login_27.gif" onClick="document.sbmtindex.reset();return false;"></td>


As you said...but is there any other changes in the beginning of the program?
i mean what the user should enter to activate the "submit" botton ?

I get the same results without mecanize.

I believe the problem is somewhere in the password or username.

The problem is that login from has to run to a javascript.

>>> from twill import get_browser
>>> b = get_browser()
>>> b.go("http://reg3.hu.edu.jo/huregister/")
==> at [url]http://reg3.hu.edu.jo/huregister/[/url]
>>> b.showforms()

Form name=sbmtindex (#1)
## ## __Name__________________ __Type___ __ID________ __Value__________________
1     user                     text      (None)        
2     pswd                     password  (None)        
3  1  submit                   image     (None)        
4  2  reset                    image     (None)        

>>>

Here we se form detail and the name off form is sbmtindex

<form name="sbmtindex" action="sbmt_index.jsp" method="POST" onsubmit="return checkValues()">

onsubmit is just ignored by mechanize, no javascript interpretation is done.
You need to verify what loginCheck(); in some limited case (Validation) you can do programmatically what javascript does.

So you need a somthing that can handle javascript,to get this to work.
Tools you can look is
http://seleniumhq.org/
http://code.google.com/p/python-spidermonkey/
selenium python bindings to control a real, running browser like Firefox or IE with javascript.

You can try to write code that do the same as javascript.
So there are possible to login but it`s take some more work from your side.

Also found DOMForm.
Client-side HTML processing with JavaScript support.
http://pypi.python.org/pypi/DOMForm/0.0.1a

This article has been dead for over six months. Start a new discussion instead.