有2个不同功能的爬虫函数,功能无耦合。
他们分别向同一个网站发出http请求。
我想使用异步httpx库的AsyncClient ,以使两个函数使用同一个session连接来进行请求。
请问以下两种写法是否都一样达到了上述的效果?谢谢
写法1:
async def a():
async with httpx.AsyncClient() as client:
response = client.get(xxxx)
return response
async def b():
async with httpx.AsyncClient() as client:
response = client.get(xxxx)
return response
写法2:
async def a(client:httpx.AsyncClient()):
response = client.get(xxxx)
return response
async def b(client:httpx.AsyncClient()):
response = client.get(xxxx)
return response
async with httpx.AsyncClient() as client:
response1 = await a(client)
response2 = await b(client)