"Python 웹에서 JSON 가져오기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(같은 사용자의 중간 판 5개는 보이지 않습니다)
3번째 줄: 3번째 줄:
;파이썬 인터넷에서 JSON 가져오기
;파이썬 인터넷에서 JSON 가져오기


<syntaxhighlight lang='python'>
==예시 1==
<syntaxhighlight lang='python' notebook>
import requests
import requests
r = requests.get('https://jsonplaceholder.typicode.com/posts/1')
r = requests.get('https://jsonplaceholder.typicode.com/posts/1')
print( r.status_code )
print( r.status_code )
# 200
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
print( r.headers['content-type'] )
print( r.headers['content-type'] )
# application/json; charset=utf8
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
j = r.json()
j = r.json()
print( type(j) )
print( type(j) )
# <class 'dict'>
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
print( j )
print( j )
# {'userId': 1, 'id': 1, 'title': 'sunt aut facere repellat provident occaecati excepturi opti reprehenderit', 'body': 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cumnreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architeco'}
</syntaxhighlight>
 
==예시 2==
<syntaxhighlight lang='python' run>
import requests
r = requests.get('https://raw.githubusercontent.com/django/django/main/package.json')
print( r.json() )
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[Python JSON 다루기]]
* [[Python JSON 다루기]]
* [[파이썬 json 파일 읽기]]
* [[Python 웹에서 파일 다운로드]]


==참고==
==참고==


[[분류: Python JSON]]
[[분류: Python JSON]]
[[분류: Python requests]]
[[분류: import requests]]

2021년 7월 13일 (화) 02:22 기준 최신판

1 개요[ | ]

Python 웹에서 JSON 가져오기
파이썬 인터넷에서 JSON 가져오기

2 예시 1[ | ]

import requests
r = requests.get('https://jsonplaceholder.typicode.com/posts/1')
print( r.status_code )
print( r.headers['content-type'] )
j = r.json()
print( type(j) )
print( j )

3 예시 2[ | ]

import requests
r = requests.get('https://raw.githubusercontent.com/django/django/main/package.json')
print( r.json() )

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}