Oct-04-2021, 02:24 PM
I will appreciate it if anyone could give me some help!
My code:
Error:
My code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import asyncio import aiohttp from lxml import etree import requests headers = { 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' } async def download(url): name = url.rsplit( '/' , 1 )[ 1 ] async with aiohttp.ClientSession() as session: async with session.get(url) as res: with open ( f '彼岸桌面壁纸下载/{name}' , 'wb' ) as f: # '彼岸壁纸下载' is a directory I builded before. f.write( await res.content.read()) async def main(): tasks = [] for url in urls: tasks.append(download(url)) await asyncio.wait(tasks) if __name__ = = '__main__' : text = requests.get(url0).text tree = etree.HTML(text) urls = tree.xpath( '/html/body/div[13]/div[1]/div/dl/dd/a/img/@src' ) asyncio.run(main()) |
Error:D:\MyPcharmProject\venv\Scripts\python.exe D:/MyPcharmProject/爬虫/Umei.py
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000023AD6F1C670>
Traceback (most recent call last):
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon
self._check_closed()
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Process finished with exit code 0
It seem that pictures have been captured. However, I can't make this error disappear even though I use try-except! 