self_example/Spider/Chapter09_代理的使用/代理的设置/aiohttpDemo.py

27 lines
518 B
Python

# -*- encoding:utf-8 -*-
'''
@Author : dingjiawen
@Date : 2023/12/13 19:54
@Usage :
@Desc :
'''
import asyncio
import aiohttp
# 普通http
proxy = 'http://127.0.0.1:7890'
# http_auth
proxy = 'http://username:password@127.0.0.1:7890'
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('https://httpbin.org/get', proxy=proxy) as response:
print(await response.text())
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())