如何记录来自aiohttp客户端的原始POST请求?

时间:2019-08-28 06:10:28

标签: logging aiohttp

我有一个与requests配合良好的POST请求,但是使用aiohttp客户端时服务器将其误解。有没有办法记录来自aiohttp客户端的原始POST请求以进行比较?

对于上下文,这就是我使用requests的方式:

url = 'https://www.places4students.com/Places/PropertyListings?SchoolID=FzhtQRDGtSU='

for next_page in range(4):
    soup = BeautifulSoup(requests.request(
        'POST', url,
        data={'__EVENTARGUMENT': f'Page${next_page}'},
        cookies={'Places4StudentDisclaimer': 'Agree'}
    ).content, 'html.parser')

这是代码的aiohttp客户端版本:

async with aiohttp.ClientSession(connector=connector) as session:
    async with session.request(
        'POST', url,
        data={'__EVENTARGUMENT': f'Page${next_page}'},
        cookies={'Places4StudentDisclaimer': 'Agree'}
    ) as response:
        content = await response.text()
        soup = BeautifulSoup(content, 'html.parser')

0 个答案:

没有答案
相关问题