2022.03.04 - [๋ฐ์ดํฐ ๋ถ์/Data Collection] - [ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(2)
[ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(2)
2022.02.10 - [๋ฐ์ดํฐ ๋ถ์/Data Collection] - [ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(1) [ํฌ๋กค๋ง] ์นํ์ด์ง์์ ๊ธฐ์ฌ ์คํฌ๋ฉ(1) ๊ธฐ์ฌ ์คํฌ๋ฉ ์นํ์ด์ง์์ ๊ธฐ์ฌ๋ฅผ ์คํฌ๋ฉ ํด์ฌ ๋ ์ด ์ธ๊ฐ์ง๋ฅผ ๊ผญ ์ํํด์ผํฉ
xod22.tistory.com
์ ๋ฒ ํฌ์คํ ์์๋ ํด๋น ์น์ฌ์ดํธ์ ๊ธฐ์ฌ ์ ๋ชฉ๊ณผ ๋งํฌ๋ง ๊ฐ์ ธ์๋ดค๋๋ฐ์..!
Title, Text, URL์ ๊ฐ์ ธ์์ ํ๋์ ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ๋ง๋๋ ์์ ์ ํด๋ณด๋ ค๊ณ ํฉ๋๋ค!

์ค์ต
1. ์ฒซ๋ฒ์งธ ๋งํฌ์์ ๊ธฐ์ฌ ํ๋ ๊ฐ์ ธ์๋ณด๊ธฐ
article1='https://www.forbes.com/sites/roberthart/2022/03/07/humanitarian-corridors-what-you-need-to-know-as-refugees-seek-safe-passage-to-leave-ukraine/'
soup2=bs(ure.urlopen(article1).read(), 'html.parser')
for i in soup2.find_all('p'):
print(i.text)
2. ๋ฉ์ธํ๋ฉด์์ ๋ณด์ด๋ ๊ธฐ์ฌ๋ค์ ๊ฐ๊ฐ url, title, text๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์๋ณด๊ฒ ์ต๋๋ค!
happening=soup.find_all('a', {"class":"happening__title"})
rows=[]
for i in range(len(happening)):
happeningtitle=happening[i].text
happeningurl=happening[i].get('href')
soup2=bs(ure.urlopen(happeningurl).read(), 'html.parser')
txt= ""
for j in soup2.find_all('p'):
txt=txt+j.text
rows.append({'Title': happeningtitle, 'URL':happeningurl, 'Text':txt})
3. rows ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๋ฐ์ดํฐ ํ๋ ์ ์์ฑ
import pandas as pd
df=pd.DataFrame(rows, columns=['Title', 'URL', 'Text'])
df