aiohttp

cooolr 于 2022-02-21 发布
import asyncio
import aiohttp

headers = {'cookie': '_omappvp=ArHoduIBLBPEVAklbkSrzMzgALHDmJosJ6iXYN9YBmGBiUYmuVnVTiEZsnEKSCh5T1rXlewpzE8hfIyVwtVxacZ8KyM9V3hv; notification-session-identifier=5e04c3d3-291d-42cf-b490-a9d00e4f768c; _omra=%7B%22fxth6telzawhaz64r83s%22%3A%22click%22%7D; _rdt_uuid=1644979041350.88b54d35-fec5-4f8a-8e2c-12cb8e228c6e; _ga=GA1.2.1202163643.1644979050; _hjSessionUser_1311473=eyJpZCI6IjU0NjRkMjU3LTJiMWUtNTI1OS1iZmYxLTc4ZGU0NTM0ODJjYSIsImNyZWF0ZWQiOjE2NDQ5NzkwNDgzNTMsImV4aXN0aW5nIjp0cnVlfQ==; _gid=GA1.2.194487257.1645403133; omSeen-fxth6telzawhaz64r83s=1644553424635; om-fxth6telzawhaz64r83s=1645408250536; cook-sec-dr=NF5MmXlceN0jsba8q3HWbRTkKJXZ00NM7gL0FIiqd4ioPqSFPFM4OpPG; test-cook=1'}

async def get(url):
    async with aiohttp.ClientSession() as session:
        response = await session.get(url=url, headers=headers, proxy="http://127.0.0.1:7890")
        text = await response.text()
        print(text)

if __name__ == "__name__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(get("http://cooolr.cn/ip"))
session = aiohttp.ClientSession(
    timeout=aiohttp.ClientTimeout(5.0)
)