开发者

convert cURL command line into python script

I'm trying to conve开发者_Python百科rt 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 "j_username=test@domain.com&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"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜