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 ?

Can you try this?

body = {'user': user, 'pswd': passo, 'submit.x': '39', 'submit.y': '7'}

i dont know....it didnt work !
maybe it needs a decleration?

Can you try this, substituting the user and pass?

import urllib

params = urllib.urlencode({'user': '0123456789', 'password': 'password', 'submit.x': '0', 'submit.y': '0'})
site = 'http://portal.hu.edu.jo:7777/huregister/index.jsp'
webpage = urllib.urlopen(site, params)
results = webpage.read()
webpage.close()
print results

and changing line 4 to:

site = 'http://portal.hu.edu.jo:7777/huregister/sbmt_index.jsp'

seems never working.....mayba ill try another language ! thax

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

wow.....all of that !
seems like impossible program for me !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.