Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,145 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
from bs4 import BeautifulSoup
|
| 4 |
-
from urllib.parse import urlparse, urljoin
|
| 5 |
-
|
| 6 |
-
# Function to fetch and extract meta tags from a URL
|
| 7 |
-
def get_meta_tags(url):
|
| 8 |
-
if not url:
|
| 9 |
-
return "Error: URL is empty. Please provide a valid URL."
|
| 10 |
-
|
| 11 |
-
# Ensure the URL starts with http(s)
|
| 12 |
-
if not url.startswith(('http://', 'https://')):
|
| 13 |
-
url = 'https://' + url
|
| 14 |
-
|
| 15 |
-
try:
|
| 16 |
-
# Fetch the webpage content
|
| 17 |
-
response = requests.get(url)
|
| 18 |
-
if response.status_code != 200:
|
| 19 |
-
return f"Error: Could not retrieve URL. Status Code: {response.status_code}"
|
| 20 |
-
|
| 21 |
-
# Parse the HTML content with BeautifulSoup
|
| 22 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
| 23 |
-
|
| 24 |
-
# Extract the meta tags
|
| 25 |
-
meta_tags = {}
|
| 26 |
-
|
| 27 |
-
# Get the <meta> tags that are important for SEO
|
| 28 |
-
title_tag = soup.title.string if soup.title else 'No Title Found'
|
| 29 |
-
description_tag = soup.find('meta', {'name': 'description'}) or soup.find('meta', {'property': 'og:description'})
|
| 30 |
-
keywords_tag = soup.find('meta', {'name': 'keywords'})
|
| 31 |
-
author_tag = soup.find('meta', {'name': 'author'})
|
| 32 |
-
|
| 33 |
-
# Safe access to meta tag content
|
| 34 |
-
meta_tags['title'] = title_tag
|
| 35 |
-
meta_tags['description'] = description_tag['content'] if description_tag and 'content' in description_tag.attrs else 'No Content Found'
|
| 36 |
-
meta_tags['keywords'] = keywords_tag['content'] if keywords_tag and 'content' in keywords_tag.attrs else 'No Content Found'
|
| 37 |
-
meta_tags['author'] = author_tag['content'] if author_tag and 'content' in author_tag.attrs else 'No Content Found'
|
| 38 |
-
|
| 39 |
-
# Extract favicon.ico URL
|
| 40 |
-
favicon_url = None
|
| 41 |
-
link_tag = soup.find('link', {'rel': 'icon'})
|
| 42 |
-
if link_tag and 'href' in link_tag.attrs:
|
| 43 |
-
favicon_url = link_tag.attrs['href']
|
| 44 |
-
|
| 45 |
-
# If favicon is relative, make it absolute
|
| 46 |
-
if favicon_url and not favicon_url.startswith('http'):
|
| 47 |
-
favicon_url = urljoin(url, favicon_url)
|
| 48 |
-
|
| 49 |
-
# Check for robots.txt and sitemap.xml
|
| 50 |
-
robots_txt = "No"
|
| 51 |
-
sitemap_xml = "No"
|
| 52 |
-
robots_txt_content = ""
|
| 53 |
-
sitemap_xml_content = ""
|
| 54 |
-
|
| 55 |
-
# Check for robots.txt and fetch its content
|
| 56 |
-
robots_response = requests.get(f"{url}/robots.txt")
|
| 57 |
-
if robots_response.status_code == 200:
|
| 58 |
-
robots_txt = "Yes"
|
| 59 |
-
robots_txt_content = robots_response.text
|
| 60 |
-
|
| 61 |
-
# Check for sitemap.xml and fetch its content
|
| 62 |
-
sitemap_response = requests.get(f"{url}/sitemap.xml")
|
| 63 |
-
if sitemap_response.status_code == 200:
|
| 64 |
-
sitemap_xml = "Yes"
|
| 65 |
-
sitemap_xml_content = sitemap_response.text
|
| 66 |
-
|
| 67 |
-
# Prepare the output in a more readable format
|
| 68 |
-
result = {
|
| 69 |
-
"meta_tags": meta_tags,
|
| 70 |
-
"favicon": favicon_url if favicon_url else "Missing",
|
| 71 |
-
"robots_txt": robots_txt,
|
| 72 |
-
"sitemap_xml": sitemap_xml,
|
| 73 |
-
"robots_txt_content": robots_txt_content,
|
| 74 |
-
"sitemap_xml_content": sitemap_xml_content
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
return result
|
| 78 |
-
|
| 79 |
-
except requests.exceptions.RequestException as e:
|
| 80 |
-
return f"Error: {str(e)}"
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
# Create the Gradio Interface
|
| 84 |
-
def format_output(result):
|
| 85 |
-
# Check if it's an error message or the actual result
|
| 86 |
-
if isinstance(result, str) and result.startswith('Error'):
|
| 87 |
-
return result
|
| 88 |
-
|
| 89 |
-
meta_tags = result["meta_tags"]
|
| 90 |
-
output = f"<h3>Meta Tags</h3>"
|
| 91 |
-
output += f"<strong>Title</strong>: {meta_tags['title']}<br>"
|
| 92 |
-
output += f"<strong>Description</strong>: {meta_tags['description']}<br>"
|
| 93 |
-
output += f"<strong>Keywords</strong>: {meta_tags['keywords']}<br>"
|
| 94 |
-
output += f"<strong>Author</strong>: {meta_tags['author']}<br><br>"
|
| 95 |
-
|
| 96 |
-
# Display favicon if present
|
| 97 |
-
favicon = result["favicon"]
|
| 98 |
-
if favicon != "Missing":
|
| 99 |
-
output += f"<h3>Favicon</h3><img src='{favicon}' alt='Favicon' style='width:50px;height:50px;'><br>"
|
| 100 |
-
else:
|
| 101 |
-
output += f"<h3>Favicon</h3><p>Missing</p><br>"
|
| 102 |
-
|
| 103 |
-
# Display robots.txt and sitemap.xml content
|
| 104 |
-
output += f"<h3>Robots.txt</h3>"
|
| 105 |
-
if result['robots_txt'] == "Yes":
|
| 106 |
-
output += f"<p>{result['robots_txt_content']}</p><br>"
|
| 107 |
-
else:
|
| 108 |
-
output += f"<p>Not found</p><br>"
|
| 109 |
-
|
| 110 |
-
output += f"<h3>Sitemap.xml</h3>"
|
| 111 |
-
if result['sitemap_xml'] == "Yes":
|
| 112 |
-
output += f"<p>{result['sitemap_xml_content']}</p><br>"
|
| 113 |
-
else:
|
| 114 |
-
output += f"<p>Not found</p><br>"
|
| 115 |
-
|
| 116 |
-
return output
|
| 117 |
-
|
| 118 |
-
# Create the Gradio Interface with a Button
|
| 119 |
-
def lookup_url(url):
|
| 120 |
-
result = get_meta_tags(url)
|
| 121 |
-
return format_output(result)
|
| 122 |
-
|
| 123 |
-
# Creating the interface with the 'Lookup' button
|
| 124 |
-
with gr.Blocks() as iface:
|
| 125 |
-
with gr.Row():
|
| 126 |
-
url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com", interactive=True)
|
| 127 |
-
lookup_button = gr.Button("Lookup URL")
|
| 128 |
-
|
| 129 |
-
output = gr.HTML()
|
| 130 |
-
|
| 131 |
-
lookup_button.click(fn=lookup_url, inputs=url_input, outputs=output)
|
| 132 |
-
|
| 133 |
-
iface.launch()
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|