I am using asyncio to get the webpage.
However, the speed is not very high.
Here is the code:
async def get_page_url(url, session):
res = await session.request(method="GET", url=url)
return await res.text()
async def main_get_page_url(urls):
async with ClientSession() as session:
tasks = [get_page_url(url, session) for province, url in urls]
result = await asyncio.gather(*tasks)
return result
if __name__ == '__main__':
urls = ['http://www.cnn.com', 'http://www.bbc.com']
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
loop = asyncio.get_event_loop()
df = loop.run_until_complete(main_get_page_url(urls))
I want to use multiprocessing.pool
and map to increase the speed.
I have searched the web but cannot find any good method.
How to modify the code?
Any other better approach?
Thank you very much