Python - Request 라이브러리 사용 16 Dec 2022 in Frontend / Python on Python , 파이썬 , Request
Request 라이브러리 사용 기본 사용 방법 import requests
URL = 'https://google.com'
response = requests . get ( URL )
response . status_code
response . text
print ( response )
print ( response . status_code )
print ( response . text )
## <Response [200]>
## 200
## <!doctype html><html itemscope="" itemtype=...</body></html>
GET 요청 시, 파라미터 전달 방법 import requests
URL = 'https://google.com'
params = { 'param1' : 'value1' , 'param2' : 'value' }
res = requests . get ( URL , params = params )
POST 요청 시, 파라미터 전달 방법 import requests
URL = 'https://google.com'
data = { 'param1' : 'value1' , 'param2' : 'value' }
res = requests . post ( URL , data = data )
import requests , json
data = { 'outer' : { 'inner' : 'value' }}
res = requests . post ( URL , data = json . dumps ( data ))
헤더 또는 쿠키의 추가 headers = { 'Content-Type' : 'application/json; charset=utf-8' }
cookies = { 'session_id' : 'sorryidontcare' }
## GET
res = requests . get ( URL , headers = headers , cookies = cookies )
## POST
res = requests . post ( URL , data = json . dumps ( data ), headers = headers , cookies = cookies )
© 2024. Chiptune93 All rights reserved. LICENSE