File size: 2,131 Bytes
01d392e
faffe39
3d0bec1
faffe39
3d0bec1
0ce76d6
3d0bec1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ce76d6
3d0bec1
 
01d392e
3d0bec1
 
 
0ce76d6
3d0bec1
 
 
 
 
 
0ce76d6
3d0bec1
 
01d392e
3d0bec1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
import requests
from bs4 import BeautifulSoup

def process_url(url, method):
    try:
        if method == "Обычный запрос":
            response = requests.get(url)
        elif method == "Через прокси":
            proxies = {
                "http": "http://your_proxy:port",
                "https": "http://your_proxy:port"
            }
            response = requests.get(url, proxies=proxies)
        elif method == "Только заголовки":
            response = requests.head(url)
            return f"Заголовки:\n{response.headers}"

        response.raise_for_status()

        if method != "Только заголовки":
            soup = BeautifulSoup(response.content, 'html.parser')
            page_title = soup.title.string if soup.title else "Нет заголовка"
            page_preview = soup.prettify()[:500]  # Ограничиваем вывод до 500 символов
            return f"Заголовок страницы: {page_title}\n\nПредварительный просмотр кода:\n{page_preview}"
        
    except requests.exceptions.RequestException as e:
        return f"Ошибка при обработке URL: {e}"

# Создаем интерфейс
with gr.Blocks() as demo:
    gr.Markdown("## Введите ссылку для просмотра исходного кода сайта")
    
    url_input = gr.Textbox(label="Введите URL", placeholder="http://example.com")
    method_selector = gr.Dropdown(choices=["Обычный запрос", "Через прокси", "Только заголовки"], 
                                  label="Метод обработки", value="Обычный запрос")
    
    submit_button = gr.Button("Отправить")
    output_text = gr.Textbox(label="Результат", lines=20)

    # Обработка нажатия кнопки
    submit_button.click(process_url, inputs=[url_input, method_selector], outputs=output_text)

# Запуск приложения
demo.launch(server_name="0.0.0.0", server_port=7860)