在异步函数中使用cloudscraper对象时出现AttributeError

发布于 2025-01-11 01:54:22 字数 602 浏览 0 评论 0原文

import cloudscraper
import requests
import asyncio
async def scrape_prices():
    scraper_object = cloudscraper.create_scraper()
    async with scraper_object as session:
        for item_number in prices_to_be_scraped:
            hyperlink = "https://opensea.io/assets/" +
            str(get_contract_address(get_project_name())) + "/" + str(
            item_number)
            async with str(scraper_object.get(hyperlink).text) as response:
                print(await response)

我进入终端时出错:

与 scraper_object 异步作为会话: 属性错误:__aenter __

import cloudscraper
import requests
import asyncio
async def scrape_prices():
    scraper_object = cloudscraper.create_scraper()
    async with scraper_object as session:
        for item_number in prices_to_be_scraped:
            hyperlink = "https://opensea.io/assets/" +
            str(get_contract_address(get_project_name())) + "/" + str(
            item_number)
            async with str(scraper_object.get(hyperlink).text) as response:
                print(await response)

ERROR IM GETTING IN TERMINAL:

async with scraper_object as session:
AttributeError: __aenter __

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2025-01-18 01:54:22

我遇到了类似的问题,我发现了这个库 https://pypi.org/project/aiocfscrape/< /a> 应该与 cloudscraper 执行相同的操作,但异步。

他们在文档中显示的使用示例是这样的:

    import asyncio
    from aiocfscrape import CloudflareScraper
    
    async def test_open_page(url):
        async with CloudflareScraper() as session:
            async with session.get(url) as resp:
                return await resp.text()

    if __name__ == '__main__':
        asyncio.run(test_open_page('<your url>'))

我希望您发现这个库很有用。

I was having a similar issue, and I found this library https://pypi.org/project/aiocfscrape/ which should be doing the same as cloudscraper does but asynchronous.

The use example that they show in the documents is this one:

    import asyncio
    from aiocfscrape import CloudflareScraper
    
    async def test_open_page(url):
        async with CloudflareScraper() as session:
            async with session.get(url) as resp:
                return await resp.text()

    if __name__ == '__main__':
        asyncio.run(test_open_page('<your url>'))

I hope you find this library useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文