Skip to main content
Beautiful Soup은 HTML과 XML 문서를 파싱하는 Python 패키지입니다(닫히지 않은 태그와 같은 잘못된 마크업도 처리 가능하며, 이러한 태그 스프(tag soup)에서 이름이 유래되었습니다). 파싱된 페이지에 대한 파스 트리를 생성하여 HTML에서 데이터를 추출하는 데 사용할 수 있으며,[3] 이는 웹 스크래핑에 유용합니다.
Beautiful Soup은 HTML 콘텐츠에 대한 세밀한 제어를 제공하여 특정 태그 추출, 제거 및 콘텐츠 정리를 가능하게 합니다. 특정 정보를 추출하고 필요에 따라 HTML 콘텐츠를 정리하려는 경우에 적합합니다. 예를 들어, HTML 콘텐츠에서 <p>, <li>, <div>, <a> 태그 내의 텍스트 콘텐츠를 스크래핑할 수 있습니다:
  • <p>: 단락 태그입니다. HTML에서 단락을 정의하며 관련된 문장이나 구절을 그룹화하는 데 사용됩니다.
  • <li>: 목록 항목 태그입니다. 순서가 있는 목록(<ol>)과 순서가 없는 목록(<ul>) 내에서 개별 항목을 정의하는 데 사용됩니다.
  • <div>: 구역 태그입니다. 다른 인라인 또는 블록 수준 요소를 그룹화하는 데 사용되는 블록 수준 요소입니다.
  • <a>: 앵커 태그입니다. 하이퍼링크를 정의하는 데 사용됩니다.
from langchain_community.document_loaders import AsyncChromiumLoader
from langchain_community.document_transformers import BeautifulSoupTransformer

# Load HTML
loader = AsyncChromiumLoader(["https://www.wsj.com"])
html = loader.load()
# Transform
bs_transformer = BeautifulSoupTransformer()
docs_transformed = bs_transformer.transform_documents(
    html, tags_to_extract=["p", "li", "div", "a"]
)
docs_transformed[0].page_content[0:500]
'Conservative legal activists are challenging Amazon, Comcast and others using many of the same tools that helped kill affirmative-action programs in colleges.1,2099 min read U.S. stock indexes fell and government-bond prices climbed, after Moody's lowered credit ratings for 10 smaller U.S. banks and said it was reviewing ratings for six larger ones. The Dow industrials dropped more than 150 points.3 min read Penn Entertainment's Barstool Sportsbook app will be rebranded as ESPN Bet this fall as '

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I