Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,26 @@
|
|
1 |
-
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
response = requests.get(url)
|
8 |
-
# BeautifulSoup ๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ HTML์ ํ์ฑํฉ๋๋ค.
|
9 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
10 |
-
# ์น ํ์ด์ง์ ํ์ดํ์ ์ถ์ถํฉ๋๋ค.
|
11 |
-
title = soup.find('title').text
|
12 |
-
return title
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
url_input = gr.Textbox(label="URL์ ์
๋ ฅํ์ธ์")
|
17 |
-
output = gr.Textbox(label="์น ํ์ด์ง ํ์ดํ")
|
18 |
-
gr.Button("์คํฌ๋ฉ").click(scrape_website, inputs=url_input, outputs=output)
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ํฌํธํฉ๋๋ค.
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
4 |
+
import pandas as pd
|
5 |
|
6 |
+
# ์น ํ์ด์ง์ URL์ ์ง์ ํฉ๋๋ค.
|
7 |
+
url = '์ฌ๊ธฐ์_์ถ์ถํ๊ณ ์_ํ๋_์นํ์ด์ง์_URL์_์
๋ ฅํ์ธ์'
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# requests๋ฅผ ์ฌ์ฉํ์ฌ ์น ํ์ด์ง์ ๋ด์ฉ์ ๊ฐ์ ธ์ต๋๋ค.
|
10 |
+
response = requests.get(url)
|
|
|
|
|
|
|
11 |
|
12 |
+
# BeautifulSoup ๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ HTML์ ํ์ฑํฉ๋๋ค.
|
13 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
14 |
+
|
15 |
+
# ์น ํ์ด์ง์ ํน์ ๋ถ๋ถ์ ์ ํํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
16 |
+
# ์์: ํ์ด์ง์ ๋ชจ๋ 'p' ํ๊ทธ์ ์๋ ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
17 |
+
# ์ค์ ์ฌ์ฉ ์ฌ๋ก์ ๋ง๊ฒ ์ ํ์๋ฅผ ์กฐ์ ํด์ผ ํฉ๋๋ค.
|
18 |
+
texts = [p.text for p in soup.find_all('p')]
|
19 |
+
|
20 |
+
# ์ถ์ถํ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
|
21 |
+
for text in texts:
|
22 |
+
print(text)
|
23 |
+
|
24 |
+
# ์ ํ์ : ์ถ์ถํ ๋ฐ์ดํฐ๋ฅผ DataFrame์ผ๋ก ๋ณํํ๊ณ ์์
ํ์ผ๋ก ์ ์ฅํฉ๋๋ค.
|
25 |
+
df = pd.DataFrame(texts, columns=['Text'])
|
26 |
+
df.to_excel('extracted_data.xlsx', index=False)
|