0

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.

1
  • 1
    The code as shown is not valid syntax. The try: must have a matching except or finally clause. Please post the traceback you get and the actual code you are using. Commented Jun 2, 2020 at 17:07

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.