

from aiohttp import TCPConnector
def __init__(self, value):
async def download_one(url):
name = url[0].split("/")[-1][:-4]
'Host': 'file.jiutuvip.com',
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, '
'like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
async with aiohttp.ClientSession(connector=TCPConnector(ssl=False)) as session:
async with session.get(url=url[0], headers=headers) as resp:
content = await resp.content.read()
async with aiofiles.open('./imgs/' + name + '.webp', "wb") as f:
async def download(self, href_list):
async with aiohttp.ClientSession(connector=TCPConnector(ssl=False)) as session:
async with session.get(url=href) as child_res:
html = await child_res.text()
child_tree = etree.HTML(html)
src = child_tree.xpath("//div[@class='article-body cate-6']/a/img/@src")
await self.download_one(src)
async def get_img_url(self, html_url):
async with aiohttp.ClientSession(connector=TCPConnector(ssl=False)) as session:
async with session.get(url=html_url) as resp:
href_list = tree.xpath("//div[@class='uk-container']/ul/li/a/@href")
await self.download(href_list)
response = requests.get(url=url)
response.encoding = "utf-8"
tree = etree.HTML(response.text)
total_page = tree.xpath("//*[@class='pages']/a[12]/text()")
next_url = f"https://www.yeitu.com/meinv/xinggan/{page}.html"
html_url_list.append(next_url)
html_url_list = self.get_html_url(url=self.start_url)
for html_url in html_url_list:
t = asyncio.create_task(self.get_img_url(html_url))
await asyncio.wait(tasks)
if __name__ == '__main__':
url = "https://www.yeitu.com/meinv/xinggan/"