본문 바로가기

Computer/Programing

Python load json from web

import json

import urllib2


url = "https://TARGET.URL"

data = json.load(urllib2.urlopen(url))


import requests

import bs4

import json



--------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------

HOW TO USE

import fxrate

fxrate.usd()

--------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------


res = requests.get('https://www.koreaexim.go.kr/site/program/financial/exchangeJSON?authkey=AUTHKEY1234567890&searchdate=20200529&data=AP01')

res.raise_for_status()

#res.encoding='euc-kr'

html = res.text


data = json.loads(html)


def usd():

#  weather = weatherlist

  for i in data:

      if i['cur_unit'] == 'USD':

          usd = i["deal_bas_r"]

          break

  return usd

--------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------