python,GET请求处理请求但不处理aiohttp

时间:2017-10-07 20:16:45

标签: python python-requests aiohttp

我正试图用aiohttp抓取ft.com网站的一页。 我开始准备使用requests进行抓取,但确实没有问题:

import requests
s = requests.session()
page= s.get("https://www.ft.com/china?page=2")

我可以看到返回的页面是正确的

print(page.text)

但是,如果我尝试使用aiohttp执行相同的抓取,则返回的页面只是一个错误页面:

import aiohttp
import asyncio
async def get_links():
    async with ClientSession() as session:
        async with session.get('https://www.ft.com/china?page=2') as response:
            response = await response.text()
            print(response)

loop = asyncio.get_event_loop()
results=loop.run_until_complete(get_links())

我可以在打印的回复中看到此页面有“错误503”

任何人都知道如何使用aiohttp抓取该页面?

0 个答案:

没有答案