블로그 이전으로 위 링크로 대체합니다.
import requests
# 세션을 생성합니다.
session = requests.Session()
# 세션을 사용해서 메인 페이지를 요청합니다.
response = session.get("https://www.example.com")
# 응답의 HTML 코드를 출력합니다.
print(response.text)
# 세션을 종료합니다.
session.close()
import requests
# 세션을 생성합니다.
session = requests.Session()
# 요청 파라미터를 지정합니다.
params = {
"search_category": "value1",
"search_query": "value2",
}
# 세션을 사용해서 GET 요청을 수행합니다.
response = session.get("https://www.example.com/search", params=params)
# 응답의 HTML 코드를 출력합니다.
print(response.text)
# 세션을 종료합니다.
session.close()
import requests
# 세션을 생성합니다.
session = requests.Session()
# 요청 데이터를 지정합니다.
data = {
"user_id": "value1",
"user_pw": "value2",
}
# 세션을 사용해서 POST 요청을 수행합니다.
response = session.post("https://www.example.com/login", data=data)
# 응답의 HTML 코드를 출력합니다.
print(response.text)
# 세션을 종료합니다.
session.close()