My English is very poor, however I can't find any useful information except the official manual when I googled this topic, so I write it down in English, hope this blog could help more people.
Keyword: cookielib http.cookiejar urllib.request login http webpagge Python 3.2
用python 3.2登入網頁 POST
I take this website for example : share.dmhy.org
In this website, you need to type your account, password, and a captcha code to login.
Step 1. Include the lib, define some var
Step 2. Create the opener, which is using cookiejar for processing cookies.
Step 3. Open the login page through opener, get captcha through opener, and save the captcha as a pic.
Step 4. Ask user for the captcha
Step 5. send POST request
Note that User-Agent is optional.
Step 6. Get responsed data, show cookies, and save cookies as "cookie.txt"
Step 7. Next time when we need to login, you just need to load "cookie.txt"