๐ BeautifulSoup - Basic
๐ฉ pip install beautifulsoup4
- from bs4 import BeautifulSoup

- html ํ์ผ์ open ๋ช ๋ น์ด๋ก ์ ์ธ, page ๋ณ์์ ๋ด์์ค๋ค
- BeautifulSoup์ page, "html. parser" ์ด์ฉ, html ํ์ผ์ ์ฝ๋๋ค
- prettify() ํจ์๋ฅผ ์ด์ฉํ์ฌ ๋ณด๊ธฐ์ข๊ฒ ์ ๋ฆฌํ๋ค

๐ฉ Tag ํ์ธ
- ํด๋์ค๋ฅผ ์ง์ ํ์ง ์์ ์, ์ฒ์ ๋ฐ๊ฒฌ๋ ํ๊ทธ๋ง ์ถ๋ ฅ ๋๋ค.



๐ find, find_all ํจ์
๐ฉ find ํจ์
- find("tag_name", class_="class_name")
- find("tag_name", {"class":"class_name"})


๐ฉ ๋ค์ค ์กฐ๊ฑด

๐ฉ text, get_text(),string, strip() ํจ์๋ก ๋ฐ์ดํฐ ๊ตฌํ๊ธฐ


- for๋ฌธ์ผ๋ก tag์ ์๋ text ๊ฐ ๊ตฌํ๊ธฐ

๐ฉ find_all ํจ์
- ํด๋น๋๋ ์ฌ๋ฌ ๊ฐ์ ํ๊ทธ๋ฅผ ๋ฆฌ์คํธ ํํ๋ก ๋ฐํ
- find_all("tag_name", class_="class_name")
- find("tag_name", {"class":"class_name"})
- find_all("tag_name", "class_name")


๐ฉ link ๊ฐ ๊ตฌํ๊ธฐ
- ํ์ดํผ๋งํฌ๊ฐ ์๋ ํ๊ทธ ๊ฐ์์ Data๋ฅผ ๊ตฌํ๋ค.
- [index]+get("href) ํจ์ / [index]+["tag"] ํจ์
- [index], get() ํจ์๋ฅผ ์ด์ฉํ์ฌ ํด๋น๋๋ link ๊ฐ์ ๊ตฌํ๋ค.

- links์ ์๋ ๊ฐ์ for๋ฌธ์ผ๋ก ์ถ์ถ

'Study_note(zb_data) > EDA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data_ํ๊ธ ์น ์ฃผ์ ํ์ธํ๊ธฐ) (0) | 2023.08.11 |
|---|---|
| ์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data 1) (0) | 2023.08.11 |
| ์คํฐ๋ ๋ ธํธ (Analysis Seoul Crime) (0) | 2023.08.08 |
| ์คํฐ๋ ๋ ธํธ (Analysis Seoul CCTV with population) (0) | 2023.08.06 |
| ์คํฐ๋ ๋ ธํธ (EDA) ๋ฐ์ดํฐ ํฉ์น๊ธฐ, matplotlib ๊ธฐ์ด (0) | 2023.08.05 |