Http post and http get

Jon Clements joncle at googlemail.com
Wed Jan 25 19:34:49 EST 2012


On Jan 25, 10:23 pm, "n3d!m" <nedimmumino... at gmail.com> wrote:
> I am writing python script which will log into openSIS (Student information system) and get grades. Demo of website is available here:http://demo.os4ed.com/
> Here is code which works for that site:
>
> #!/usr/bin/python
> import requests
> user_login={'USERNAME':'student','PASSWORD':'student'}
> r=requests.post("http://demo.os4ed.com/index.php", data=user_login)
> r=requests.get("http://demo.os4ed.com/for_export.php?modname=Grades/Transcripts.php&m...[]=1", cookies=r.cookies)
> print r.text
>
> My problem is when I try the same thing with my school's openSIS. It returns me error:
> <SCRIPT language=javascript>history.back();alert("You must choose at least one student and marking period");</SCRIPT>
>
> Their openSIS is installed on port 8080. Does port 8080 causes problem with my script?

Why do you think a port number would make a difference? As long as the
URI you're connecting to, correctly routes to something handling HTTP
- it doesn't matter - and since you're getting "script" tags back, it
implies it does.

I think the response you're getting says it all, although:
1) It should be "javascript" instead of javascript (tho' most of the
time it's omitted)
2) Can't fathom why the history.back() precedes the alert("...")
3) It's normally more polite to go to an error page with an <a
href="...">whatever</a> instead of an alert

For stuff like this, I would use Firefox with Firebug, and manually go
through the process of doing what you're doing, getting where the
posts go etc... etc..., and then try and mimic that.

ie, you find out where submissions take place and what data you
retrieve, it might be that you just require a session cookie and then
can by-pass pretty much all the intermediate pages.

If pages are AJAX generated, it's quite a bit more work, you'll either
need to run some form of web engine, or automate a browser using
selenium. Then you should be able to use lxml.html to parse the DOM
the browser has generated.

hth,

Jon.




More information about the Python-list mailing list