"뷰티플 수프"의 두 판 사이의 차이

32번째 줄: 32번째 줄:
* [[Selenium]]
* [[Selenium]]
* [[태그 수프]]
* [[태그 수프]]
* [[Python requests]]
* [[파이썬 requests]]


==참고==
==참고==

2021년 6월 5일 (토) 21:39 판

1 개요

Beautiful Soup
뷰티풀 수프
  • HTML과 XML 문서를 파싱하는 파이썬 패키지
  • 잘못 쓴 태그, 안닫힌 태그 등 소위 '태그 수프'를 잘 처리할 수 있다.

Bs4-doc-image-6.1.jpg

2 예시 1

from bs4 import BeautifulSoup
print(BeautifulSoup("<html><head></head><body>Sacr&eacute; bleu!</body></html>", "html.parser"))
HTML 엔티티가 유니코드 문자로 변환되었다.

3 예시 2

  • 웹 상의 HTML 페이지를 읽어와서 파싱한다.
  • requests와 함께 사용한 예시
import requests
from bs4 import BeautifulSoup

r = requests.get('https://en.wikipedia.org/wiki/Main_Page')
soup = BeautifulSoup(r.text, 'html.parser')
for anchor in soup.find_all('a'):
    print(anchor.get('href', '/'))

4 같이 보기

5 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}