I am coming from a C# background and Python's Asyncio library is confusing me.
I have read the following 1 2, yet the use of asyncio remains unclear to me.
I am trying to make a website scraper in python that is asynchronous.
async def requestPage(url):
request = requests.get(url, headers=headers)
soup = BeautifulSoup(request.content, 'html.parser')
return soup
async def main():
#****** How do I run an async task and store its result to use in another task?
index_soup = asyncio.ensure_future(requestPage(index_url))
res = asyncio.gather(index_soup)
currency_urls = res.select('a[href^="/currencies"]')
print(currency_urls)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.close()