小编Hon*_*Bee的帖子

从python的协程对象中检索数据

我正在尝试学习异步,现在我正在尝试获取一批域的 whois 信息。我找到了这个 lib aiowhois,但是只有几笔信息,对于我这样的新手来说还不够。

这段代码没有错误,但我不知道如何从解析的whois变量中打印数据,这是协程对象。

resolv = aiowhois.Whois(timeout=10)

async def coro(url, sem):
    parsed_whois = await resolv.query(url)

async def main():
    tasks = []
    sem = asyncio.Semaphore(4)

    for url in domains:
        task = asyncio.Task(coro(url, sem))
        tasks.append(task)
    await asyncio.gather(*tasks)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Run Code Online (Sandbox Code Playgroud)

python whois coroutine python-asyncio python-3.7

5
推荐指数
2
解决办法
5299
查看次数

标签 统计

coroutine ×1

python ×1

python-3.7 ×1

python-asyncio ×1

whois ×1