POST送信・Cookie管理

  • POST送信

Python

import urllib2
params = urllib2.urlencode({'name': 'foo', 'pass': 1234, 'location': 'Japan'})
f = urllib2.urlopen("http://example.com/cgi-bin/query", params)

Perl

use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');
$res = $ua->request($req);

Python(2.4以降)

import urllib2, cookielib   # Python 2.4以降
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://www.example.com/")

Perl

use LWP::UserAgent;
use HTTP::Cookies;
$ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1));
$res = $ua->request(HTTP::Request->new(GET => "http://www.example.com"));

メモメモ。