LoginSignup
1
2

More than 5 years have passed since last update.

urllibでjsonデータを取得する際の流れメモ

Last updated at Posted at 2015-07-14

参考ページ

point

data 引数を渡さない場合、urllib2 は GET リクエストを利用します。

ってことは引数を渡せばPOSTとなる

サンプル

import urllib
import urllib2
import json

url = 'http://api.hoge.json'
params = {
'status': 1
}
data = urllib.urlencode(params)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json_acceptable_string = response.read().replace("'", "\"")
data = json.loads(json_acceptable_string)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2