2022.02.10 - [๋ฐ์ดํฐ ๋ถ์/Data Collection] - [ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(1)
[ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(1)
๊ธฐ์ฌ ์คํฌ๋ฉ ์นํ์ด์ง์์ ๊ธฐ์ฌ๋ฅผ ์คํฌ๋ฉ ํด์ฌ ๋ ์ด ์ธ๊ฐ์ง๋ฅผ ๊ผญ ์ํํด์ผํฉ๋๋ค! article=Article("https://www.3gpp.org/news-events/2143-3gpp-meets-imt-2020") article.download() article.parse() 1. ๋งํฌ..
xod22.tistory.com
์ด๋ฒ ํฌ์คํ ์์๋ BeautifulSoup ํจํค์ง๋ฅผ ์ฌ์ฉํด์ ํฌ๋กค๋ง ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๊ณต๋ถํด๋ณด๋ ค๊ณ ํฉ๋๋ค!
์ค์ต
1. ํจํค์ง ์ํฌํธ
import urllib.request as ure
from bs4 import BeautifulSoup as bs
2. ๋งํฌ ์ ์ฅ ๋ฐ ์น์ฌ์ดํธ ๊ตฌ์กฐ ๊ฒํ
#ํฌ๋กฌ ๋ทฐ์์ค(F12)๋ก HTML๊ตฌ์กฐ๋ฅผ ์ดํด๋ด!
#์น์ฌ์ดํธ๋ ์ ์ฌํ์ง๋ง ๊ตฌ์กฐ๊ฐ ๋ค๋ฅด๋ฏ๋ก ๊ตฌ์กฐ๋ฅผ ๊ฒํ ํด์ผํจ!
news='https://www.forbes.com/'
soup=bs(ure.urlopen(news).read(), 'html.parser')
soup.find_all('a', {"class":"happening__title"})
*F12๋ฅผ ๋๋ฅด๋ฉด ๋ค์๊ณผ ๊ฐ์ ํ๋ฉด์ด ๋ํ๋๋๋ฐ main class์ ํ์์ฝ๋๋ฅผ ๋ณด๋ฉด์
aํ๊ทธ๋ฅผ ์ฐพ์์ผํ๋ค.
ํ์์ฝ๋๋ฅผ ๋ณด๋ค๋ณด๋ฉด <a class="happening__title"~~์ด ๋ํ๋๋ค. ์ด๊ฒ์ ์ฐพ์์ ์ฝ๋์ ๋ฃ์ด์ค์ผํ๋ค..!
3. ํ ์คํธ ๋ฐ์ดํฐ ์ ์ฅ
for i in soup.find_all('a', {"class":"happening__title"}):
print(i.text)
4. ๋งํฌ ๋ฆฌ์คํธ ์ ์ฅ
for i in soup.find_all('a',{"class":"happening__title"}):
print(i.get('href'))