You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from django_unicorn.components import UnicornView
import requests
from bs4 import BeautifulSoup
class ContcompView(UnicornView):
url = "https://example.com"
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'
}
cuenta = dict()
palabras = []
def count(self,*args,**kwargs):
self.page = requests.get(self.url)
self.data = self.page.text
self.soup = BeautifulSoup(self.data,features="html.parser")
self.text = self.soup.get_text()
self.palabras = self.text.split()
self.auxpalabras = []
for palabra in self.palabras:
if palabra in self.cuenta:
self.cuenta[palabra] += 1
else:
self.cuenta[palabra] = 1
self.auxpalabras.append(palabra)
self.palabras = self.auxpalabras
And this on my .htm file component
<div>
<form unicorn:submit.prevent="add">
<input class="textinput textInput form-control" type="text" unicorn:model.lazy="url" placeholder="url" id="url"></input>
</form>
<button class="btn btn-outline-info" unicorn:click="count">Contar Palabras</button>
<!-- TODO: Check box si se desea incluir articulos -->
<!-- TODO: Mostar pagina de espera mientras se realiza el scraping -->
<p>
{% if palabras %}
<ul>
{% for key, val in cuenta.items %}
<li>{{key}}: {{val}}</li>
{% endfor %}
</ul>
<button class="btn btn-outline-info" unicorn:click="$reset">Limpiar</button>
{% else %}
Agregue una dirección url y haga click en el boton para contar las palabras en la pagina web, el proceso es algo lento, dependiendo del contenido de la pagina.
{% endif %}
</p>
</div>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have this on my .py file component
And this on my .htm file component
If I run the code and the url get small text as https://example.com it runs ok, but when I run something with much text as https://es.wikipedia.org/wiki/Castell%C3%B3n_de_la_Plana I get the "RecursionError: maximum recursion depth exceeded while getting the str of an object"
Does anyone has a workaround for this?
Beta Was this translation helpful? Give feedback.
All reactions