Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 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 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.3"
|
| 32 |
-
}
|
| 33 |
-
response = requests.get(url, headers=headers)
|
| 34 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
| 35 |
-
search_results = soup.find_all('div', attrs={'class': 'tF2Cxc'})
|
| 36 |
-
all_results.extend(search_results)
|
| 37 |
-
|
| 38 |
-
for i, result in enumerate(all_results[:num_results]):
|
| 39 |
-
header = result.find('h3')
|
| 40 |
-
header = header.text if header else "Sin t铆tulo"
|
| 41 |
-
link = result.find('a', href=True)['href']
|
| 42 |
-
link_clean = re.search("(?P<url>https?://[^\s]+)", link).group("url")
|
| 43 |
-
dominio_resultado = urlparse(link_clean).netloc
|
| 44 |
-
|
| 45 |
-
estilo_dominio = ""
|
| 46 |
-
if dominio_objetivo in dominio_resultado:
|
| 47 |
-
posiciones_dominio.append(i + 1)
|
| 48 |
-
if link_clean == url_objetivo:
|
| 49 |
-
posiciones_dominio_exacto.append(i + 1)
|
| 50 |
-
estilo_dominio = estilo
|
| 51 |
else:
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if len(posiciones_dominio) > 1 and 1 in posiciones_dominio:
|
| 59 |
-
mensaje = f"Parasitaci贸n SEO: {url_objetivo} se encuentra en las posiciones {posiciones_dominio} 馃"
|
| 60 |
-
estilo = "font-size:19px; color: #ffd700;"
|
| 61 |
-
elif len(posiciones_dominio) > 1:
|
| 62 |
-
mensaje = f"Canibalizaci贸n: {url_objetivo} se encuentra en las posiciones {posiciones_dominio} 馃槙"
|
| 63 |
-
estilo = "font-size:19px; color: #ed4b4b;"
|
| 64 |
-
elif len(posiciones_dominio) == 1 and len(posiciones_dominio_exacto) == 0:
|
| 65 |
-
mensaje = f"Canibalizaci贸n: URL diferente del dominio en la posici贸n {posiciones_dominio[0]} 馃槙"
|
| 66 |
-
elif len(posiciones_dominio) == 1:
|
| 67 |
-
mensaje = f"Sin canibalizaci贸n: {url_objetivo} se encuentra en la posici贸n {posiciones_dominio[0]} 馃槙"
|
| 68 |
-
estilo = "font-size:19px; color: #26d52d;"
|
| 69 |
-
else:
|
| 70 |
-
mensaje = f"{url_objetivo} no se encuentra en el top 100 馃槙"
|
| 71 |
-
estilo = "font-size:19px; color: #ed4b4b;"
|
| 72 |
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
mensaje, tabla = buscar_google(keyword, url)
|
| 77 |
-
return mensaje, tabla
|
| 78 |
|
| 79 |
iface = gr.Interface(
|
| 80 |
-
fn=
|
| 81 |
-
inputs=
|
| 82 |
-
outputs=
|
| 83 |
-
title="
|
| 84 |
-
description="
|
| 85 |
-
article="<p style='text-align:center !important;'>Desarrollada por <a style='text-decoration:none !important;color:#e12a31 !important;' href='https://artxeweb.com'>漏 Artxe Web</a></p>",
|
| 86 |
)
|
| 87 |
|
| 88 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
+
import urllib.parse
|
| 5 |
+
|
| 6 |
+
def fetch_suggestions(query, lang_code="es"):
|
| 7 |
+
encoded_query = urllib.parse.quote(query)
|
| 8 |
+
url = f"http://suggestqueries.google.com/complete/search?client=firefox&hl={lang_code}&q={encoded_query}"
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
if response.status_code == 200:
|
| 11 |
+
return response.json()[1]
|
| 12 |
+
else:
|
| 13 |
+
return []
|
| 14 |
+
|
| 15 |
+
def expand_keyword(keyword):
|
| 16 |
+
expanded_keywords = [keyword]
|
| 17 |
+
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 18 |
+
expanded_keywords.append(keyword + " " + letter)
|
| 19 |
+
expanded_keywords.append(letter + " " + keyword)
|
| 20 |
+
return expanded_keywords
|
| 21 |
+
|
| 22 |
+
def main(keyword):
|
| 23 |
+
expanded_keywords = expand_keyword(keyword)
|
| 24 |
+
all_suggestions = {}
|
| 25 |
+
|
| 26 |
+
for exp_keyword in expanded_keywords:
|
| 27 |
+
suggestions = fetch_suggestions(exp_keyword)
|
| 28 |
+
for suggestion in suggestions:
|
| 29 |
+
if suggestion in all_suggestions:
|
| 30 |
+
all_suggestions[suggestion] += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
else:
|
| 32 |
+
all_suggestions[suggestion] = 1
|
| 33 |
|
| 34 |
+
# Convertir el diccionario en un DataFrame de Pandas
|
| 35 |
+
df = pd.DataFrame(list(all_suggestions.items()), columns=['Sugerencias de Google', 'Frecuencia'])
|
| 36 |
|
| 37 |
+
# Filtrar el DataFrame para mostrar solo las sugerencias con una frecuencia de al menos 2
|
| 38 |
+
df_filtered = df[df['Frecuencia'] >= 2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Ordenar el DataFrame seg煤n la frecuencia
|
| 41 |
+
df_sorted = df_filtered.sort_values(by=['Frecuencia'], ascending=False)
|
| 42 |
|
| 43 |
+
return df_sorted
|
|
|
|
|
|
|
| 44 |
|
| 45 |
iface = gr.Interface(
|
| 46 |
+
fn=main,
|
| 47 |
+
inputs="text",
|
| 48 |
+
outputs="dataframe",
|
| 49 |
+
title="Generador de Sugerencias de B煤squeda de Google",
|
| 50 |
+
description="Ingrese una palabra clave para obtener sugerencias de b煤squeda relacionadas de Google."
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
iface.launch()
|