前面博客讲的太泛了,对于我搞爬虫就细化学习理解一波,基于这篇博客的学习
由于requests库和asyncio库是不能一起使用的,所以我们要安装一点小插件pip install aiohttp
先上代码
import asyncio
import aiohttp
async def func(url):
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
}
print('开始下载',url)
async with aiohttp.ClientSession() as session:
async with await session.get(url=url,headers=headers) as response:
data = await response.read()
name = url.split