BeautifulSoup CheatSheet

nara_lee·2025년 4월 24일
1
post-thumbnail

1. find()

title = soup.find("h1")
print(title.text)

2. find_all()

links = soup.find_all("a")
for link in links:
	print(link.get("href"))

3. select() CSS 선택자 방식으로 찾기

titles = soup.select("div.article > h2.title")
for t in titles:
	print(t.text)

⚠️ Selector Combination

4. select_one() CSS 선택자 방식 중 첫 번째만

titles = soup.select_one("div.article h2.title")
print(title.text)

5. get_text() or .text: 텍스트만 추출

paragraph = soup.find("p")
print(paragraph.get_text())

6. get("속성"): 속성 값 가져오기

image = soup.find("img")
print(image.get("src"))

본 후기는 [한글과컴퓨터x한국생산성본부x스나이퍼팩토리] 한컴 AI 아카데미 (B-log) 리뷰로 작성 되었습니다.

#한컴AI아카데미 #AI개발자 #AI개발자교육 #한글과컴퓨터 #한국생산성본부 #스나이퍼팩토리 #부트캠프 #AI전문가양성 #개발자교육 #개발자취업

0개의 댓글