#navi(../)
* Pythonでurllib2を使用したGETのサンプルコード [#tf7709d8]
Pythonのurllib2モジュールを利用したHTTPのサンプルコードを以下に記します。

#contents
#htmlinsertpcsp(ll-top.html,ll-sp.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のサンプルコードでした。

#htmlinsertpcsp(ll-btm.html,ll-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS