0

Im a python beginner, so please sorry for my question. I try to write a script in python, acutally the script use linux bash, python and php. This script was not written by me, so it is not easy to understand every point. I would do now everything in python, cause i think this is the better way and it should work then on every system, not only on linux.

I need the following line "translated" to python:

curl -s --cookie-jar "$COOKIE_DIR/$SAVE_COOKIE" -b "$COOKIE_DIR/$LOAD_COOKIE" --data "$QUERY_STRING" "$URL" > "$TEMP_FILE""_bak"

I need to save and load the cookies. Also must send a post data. So, how i do this? With "requests" or urllib or mechanize?

Many thx for helping me.

battleck
  • 13
  • 1
  • 4

1 Answers1

0

To convert this curl into python, first you have to understand what are the commandline parameters doing here. You can easily check these from the curl's man page.

Now, to implement it in Python, the libraries you have mentioned are all capable to do it (except urllib or urllib2, its slightly harder compare to the other twos).

Here is an example about how the requests is using cookiejar in combined with cookielib of Python. And here is an example of how you can post data using requests. As you feel comfort with Python, you can easily combine these two into a single code I believe. If not, then show us what you have done so far and we can continue from there!

Community
  • 1
  • 1
Sabuj Hassan
  • 35,286
  • 11
  • 68
  • 78
  • Thanks for your links, but that not helping me. Saving and loading cookies is not easy with cookiejar. Never two lines :/ – battleck Feb 07 '14 at 07:51