I'd like to use method assesion.run(), which expects pointers to async functions. Number of functions differs, so I tried to make a list of functions and spread it in .run() arguments section. But when appending them to list, they immediately invoke. How to generate variable number of functions please?
from requests_html import AsyncHTMLSession
asession = AsyncHTMLSession()
urls = [
'https://python.org/',
'https://reddit.com/',
'https://google.com/'
]
async def get_html(url):
r = await asession.get(url)
return r
functionList = []
for url in urls:
functionList.append(get_html(url))
# results = asession.run(fn1, fn2, fn3, fn4, ...)
results = asession.run(*functionList)
for result in results:
print(result.html.url)
threadingmodule orconcurrent.futuresmodel to build out a que.functionList.append(lambda url=url: get_html(url))