#!/usr/bin/env python3
from requests_html import HTMLSession
@service
def scrape_web(url=None, entity_id=None):
def sesja(url):
session = HTMLSession()
r = task.executor(session.get, url)
#r.html.render() # to nie działa
title = r.html.find("h1", first=True)
return title
a = sesja(url)
log.info(a.text)
state.set(entity_id, value=a.text)
2022-12-29 18:52:54.680 ERROR (MainThread) [custom_components.pyscript.file.test.scrape_web] Exception in line 12:
r.html.render() # to nie działa
^
RuntimeError: Cannot use HTMLSession within an existing event loop. Use AsyncHTMLSession instead.