w1_bs4 - steelbear/HMG_Softeer_DE GitHub Wiki
Beautiful Soup 4
- HTML์ด๋ XML๊ณผ ๊ฐ์ ๋งํฌ์
์ธ์ด๋ก ์์ฑ๋ ํ
์คํธ ํ์ฑ์ ๋์์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
from bs4 import BeautifulSoup
soup = BeautifulSoup(text, 'html.parse') # (ํ์ฑํ ํ
์คํธ, ํ์ฑ ํจ์)
soup.find('a') # ๊ฐ์ฅ ๋จผ์ ๋ฐ๊ฒฌ๋๋ ํ๊ทธ ์ฐพ๊ฐ
# attribute ์ถ๊ฐ๋ก ๊ฒ์
tag = soup.find('a', href='...')
soup.find('a', classes=['...'])
soup.find('a', attrs={'value': '0'})
# ํด๋นํ๋ ๋ชจ๋ ํ๊ทธ ๊ฒ์
soup.findall('a')
# ํ๊ทธ ์ ์ปจํ
์ธ
tag.content
tag.text
# ๋ถ๋ชจ, ์์, ํ์ ํ๊ทธ
tag.parent
tag.child
tag.children
tag.next_sibling
tag.prev_sibling
# ๊ฒ์์ผ๋ก ๋ถ๋ชจ ํ๊ทธ์ ํ์ ํ๊ทธ ๊ฒ์
tag.find_parent(...)
tag.find_next_sibling(...)