asyncwith aiohttp.ClientSession() as session: # 登陆一下cookieClientSession共享 await session.post(self.login_url, data=self.login_data) asyncwith session.post(self.url, data=data) as response: returnawait response.text()
# 协程+异步 defasync_aio(self): tasks = [asyncio.ensure_future(self.request_and_get_result(n)) for n inrange(1, 8)] loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(tasks)) for task in tasks: print(task.result())
if __name__ == '__main__': a = ImportOrder() a.async_aio()