[python] module: requests HTTP protocol handler

markyang92·2021년 8월 30일
0

python

목록 보기
27/42
post-thumbnail
post-custom-banner

출처: https://docs.python-requests.org/en/latest/

  • import requests

get

import requests
r = requests.get('URL')

requests.get(args..) -> class requests.Response object
S/Freturn
성공class requests.Response 오브젝트
실패-

Response object

  • class requests.Response object, contains a server's response to an HTTP request.
import requests
r = requests.get('URL')

requests.get(args..) -> class requests.Response object

close()

import requests
r = requests.get('URL')
r.close()
  • Release the connection back to the pool.
  • Once this method has been called the underlying raw object. Must not be accessed again
  • NOTE : Should not normally need to be called explicitly.

content

  • Content of the response, in bytes.

text

  • Content of the response, in unicode.
  • If response.encoding = None, encoding will be guessed using charset_normalizer or chardet
  • The encoding of the response content is determined based solely on HTTP headers.
    following RFC 2616 to the letter.
    If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you shoould set response(object).encoding appropriately before accessing this property.

import requests

r = requests.get('URL')
print(r.text)
# URL의 response를 unicode로 담고 있음 이를 출력

text with FILE I/O

import requests

r=requests.get('URL')

encoding=None

  • Encoding to decode with when accessing r.text
import requests

r = requests.get('URL')
r.encoding='utf-8'
print(r.text)
profile
pllpokko@alumni.kaist.ac.kr
post-custom-banner

0개의 댓글