Requests-html: Error While Running On Flask
I've prepared a script that was using requests-html which was working fine. I deployed it in the flask app and now it's giving me RuntimeError: There is no current event loop in th
Solution 1:
You should use Quart library built on top of flask. That will solve your problem.
Installation: pip install quart
from quart import Quart
from requests_html import AsyncHTMLSession
app = Quart(__name__)
@app.route('/<user>')defhello_world(user):
session = AsyncHTMLSession()
r = await session.get('https://medium.com/@' + str(user))
print(r)
await r.html.arender()
divs = r.html.find('div')
lst = []
for div in divs:
soup = BeautifulSoup(div.html, 'html5lib')
div_tag = soup.find()
try:
title = div_tag.section.div.h1.a['href']
if title notin lst:
lst.append(title)
except:
pass
Post a Comment for "Requests-html: Error While Running On Flask"