hypertext transfer protocol
| 요청 | 응답 |
|---|---|
| request | response |
| client | server |
hypertext markup language
외부 라이브러리 이므로 설치 해야한다.
pip install requests
import requests
url = "https://www.naver.com/"
response = requests.get(url)
status = response.status_code
html = response.text
print(status) # 200
| 코드 | 내용 |
|---|---|
| 200 | 요청 성공 |
| 302 | 다른페이지로 바로 연결 |
| 400 | Bad Request / 요청 잘못됨 |
| 401 | Unauthorized / 비인증 |
| 403 | Forbidden / 접근 권한 없음 |
| 404 | Not Found / 경로를 찾을수 없음 / 요청 받은 내용이 없음 |
| 405 | Method Not Allowed / 접근 방법 잘못됨 |
| 500 | Internal Server Error / 서버 에러 |
| 501 | Not Implemented |
| 502 | Bad Gateway / 잘못된 응답 |
프로토콜://호스트주소:포트번호/경로?쿼리
from bs4 import BeautifulSoup
html = "<html><body>Hello</body></html>"
soup = BeautifulSoup(html, "html.parser")
print(soup.body) # <body>Hello</body>
print(soup.body.text) # Hello