File size: 728 Bytes
5b573f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
import requests
from bs4 import BeautifulSoup

def scrape_website(url):
    # μ›Ή νŽ˜μ΄μ§€μ˜ λ‚΄μš©μ„ κ°€μ Έμ˜΅λ‹ˆλ‹€.
    response = requests.get(url)
    # BeautifulSoup 객체λ₯Ό μƒμ„±ν•˜μ—¬ HTML을 νŒŒμ‹±ν•©λ‹ˆλ‹€.
    soup = BeautifulSoup(response.text, 'html.parser')
    # μ›Ή νŽ˜μ΄μ§€μ˜ 타이틀을 μΆ”μΆœν•©λ‹ˆλ‹€.
    title = soup.find('title').text
    return title

with gr.Blocks() as demo:
    gr.Markdown("### μ›Ή μŠ€ν¬λž˜ν•‘ ν”„λ‘œκ·Έλž¨")
    url_input = gr.Textbox(label="URL을 μž…λ ₯ν•˜μ„Έμš”")
    output = gr.Textbox(label="μ›Ή νŽ˜μ΄μ§€ 타이틀")
    gr.Button("슀크랩").click(scrape_website, inputs=url_input, outputs=output)

if __name__ == "__main__":
    demo.launch()