Asyncio如何修复sys:1:RuntimeWarning:从未等待协程'xxx'

时间:2020-10-14 18:12:02

标签: python python-asyncio

构建一个刮板以异步刮刮多个页面。我创建了一个类,但是一旦我想运行测试方法,就会收到2个错误:

TypeError: 'coroutine' object is not callable
sys:1: RuntimeWarning: coroutine 'Scraper.page' was never awaited

这是我的代码:

from requests_html import AsyncHTMLSession

class Scraper(AsyncHTMLSession):
    def __init__(self):
        AsyncHTMLSession.__init__(self)
    
    async def page(self):
        t = await self.get("https://www.somePage.pl/strona/1/")

if __name__ == "__main__":
    t = Scraper()
    d1 = t.run(t.page())
    print(d1.result)

0 个答案:

没有答案