Reputation: 4577
I'm trying to asynchronously load content of a web page. I have used requests_html, as I face some problem installing it on my server so I am using asyncio
@asyncio.coroutine
async def extract_feature():
try:
count = 0
key = ''
loop = asyncio.get_event_loop()
response = await loop.run_in_executor(None, requests.get, link)
soup = BeautifulSoup(response, "html.parser")
return soup
loop = asyncio.get_event_loop()
result = loop.run_until_complete(extract_feature)
But this raises A Future or coroutine is required.
One thing to mentioned I'm using Python 3.5.0 (v3.5.0:374f501f4567) which doesn't support run.
Upvotes: 0
Views: 262
Reputation: 155670
You need to call extract_feature
before passing it to run_until_complete
, i.e.:
result = loop.run_until_complete(extract_feature())
Also, the asyncio.coroutine
decorator shouldn't be used with functions already defined as async def
- just omit it.
Upvotes: 2