Beautifulsoup - 파이썬패키지

찌니·2021년 3월 15일
0

BeautifulSoup가 필요한 이유

requests.text를 이용해 가져온 데이터는 텍스트형태의 html 입니다.
텍스트형태의 데이터에서 어떻게 원하는 html 요소에 접근할 수 있을까요?
이를 쉽게 할 수 있게 도와주는 녀석이 바로 "뷰티풀수프"입니다!!
즉, 날 것의 html을 의미있는 객체로 만들어서 사용자가 요리하기 쉽게 만드는 겁니다.

설치

pip install beautifulsoup4

사용법

import requests
from bs4 import BeautifulSoup

url = 'http://google.com'

response = requests.get(url)

if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')
    print(soup)

else : 
    print(response.status_code)

응답 코드가 200 일때, html 을 받아와 soup 객체로 변환 합니다.
200번 코드가 나오면 성공!
HTTP 상태코드

profile
https://gggggeun.tistory.com/

0개의 댓글