Spaces:
Sleeping
Sleeping
File size: 1,131 Bytes
b874025 b25b52b b874025 b25b52b b874025 0508087 b25b52b b874025 |
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 |
# app.py
import gradio as gr
from selectolax.parser import HTMLParser
import requests
def parse_url(url):
try:
response = requests.get(url)
response.raise_for_status()
parser = HTMLParser(response.text)
# Extract the desired information from the parsed HTML
text_content = parser.text()
# Extract specific elements if needed, for example, all paragraph texts
paragraphs = [node.text() for node in parser.css('p')]
# Combine the extracted information into a single string
output = r"""Text Content:
{text_content}
Paragraphs:
{'\n'.join(paragraphs)}"""
return output
except Exception as e:
return f"Error: {str(e)}"
# Create the Gradio interface
iface = gr.Interface(
fn=parse_url,
inputs="text", # Input is a text box for the URL
outputs="text", # Output is a text box for the parsed content
title="URL Parser",
description="Enter a URL to parse the page using Selectolax and output the information."
)
# Launch the Gradio app
if __name__ == "__main__":
iface.launch() |