#navi(../)
* Pythonでurllib2を使用したGETのサンプルコード [#tf7709d8]
Pythonのurllib2モジュールを利用したHTTPのサンプルコードを以下に記します。
#contents
//#htmlinsert(ll_ads_top.html)
* サンプルコード [#qb4741ba]
HTMLボディとHTTPコードおよびメッセージ、HTMLボディをリスト(配列)にセットするサンプルコードを以下に紹介します。
** ボディを取得するサンプルコード [#ga0f6bcb]
import urllib2
r = urllib2.urlopen('http://ll.just4fun.biz/')
print r.read()
** HTTPコードとメッセージを取得するサンプルコード [#xeb4769f]
import urllib2
r = urllib2.urlopen('http://ll.just4fun.biz/')
print "geturl() = " + r.geturl()
print "code = ", r.code
print "msg = ", r.msg
** ボディをリストにセットするサンプルコード [#vc4d8ed9]
import urllib2
r = urllib2.urlopen('http://ll.just4fun.biz/')
print r.readlines()
以上、Pythonのurlllib2モジュールを使用したHTTP GETのサンプルコードでした。
//#htmlinsert(ll_ads_btm.html)