我正在嘗試異步加載網(wǎng)頁內(nèi)容。我使用過requests_html,因?yàn)槲以诜?wù)器上安裝它時(shí)遇到一些問題所以我使用asyncio@asyncio.coroutineasync 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 souploop = asyncio.get_event_loop()result = loop.run_until_complete(extract_feature)但這會(huì)引發(fā)A Future 或 coroutine is required。要提到的一件事是我使用的是不支持運(yùn)行的Python 3.5.0 (v3.5.0:374f501f4567) 。
1 回答

狐的傳說
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
您需要extract_feature
在將其傳遞給之前致電run_until_complete
,即:
result = loop.run_until_complete(extract_feature())
此外,asyncio.coroutine
裝飾器不應(yīng)該與已經(jīng)定義為的函數(shù)一起使用async def
——忽略它即可。
添加回答
舉報(bào)
0/150
提交
取消