I'm trying to convert these sequence of CURL commands into python script. Can someone assist me on this please? There should be function/method for command 3 and 4 below which will accept the parameter as "data" to pass to command 3 below and note to process as query argument in command 4 below(eg. of node in command 4 below: cid=29-0&pid=12&gid=29-0&type=1")
curl --cookie-jar /mydir/cookies.tmp -o dev/null "http://xyz:8080/main/main.faces"
curl --cookie /mydir/cookies.tmp --location --cookie-jar /mydir/cookies.tmp --data "[email protected]&j_password=test" -o /dev/null "http://xyz.com:8080/main/j_sec_check"
curl --cookie /mydir/cookies.tmp --data "cmd=u&rid=5&cid=29-0&pid=12&gid=29-0&type=1&blablblablablablablablblablablablablablblablablablablablblablablabla" "http://xyz.com:8080/main/rest/testrestXML"
curl --cookie /mydir/cookies.tmp "http://xyz.com:8080/main/rest/process?cid=29-0&pid=12&gid=29-0&type=1"
-
I usually do, but if I have missed any then I'm sorry. I will make sure moving forwarddoneright– doneright2011年01月04日 20:53:45 +00:00Commented Jan 4, 2011 at 20:53
1 Answer 1
Well, without doing it all for you, start with urllib2. The relevant function is urllib2.urlopen("http://www.example.com"). If you pass a second parameter, it is treated as the data in a POST request. To do a GET request, just add url encoded parameters to the URL. urllib (without the 2) has a urlencode function if you need it.
If you need to use cookies, use cookielib. The examples for it show you how.