我在 python 中編寫了一個腳本,用于從 Torrent 站點下載不同的電影圖像并將它們存儲在桌面的文件夾中。我的腳本可以下載圖像并將其保存在一個文件夾中。如果文件夾中沒有圖像或所有圖像都在,我的腳本可以處理下載或不下載的過程。如果某些圖像已經在文件夾中,如何讓我的腳本下載其余的圖像?這是我的嘗試:import osimport requestsfrom bs4 import BeautifulSoupfrom urllib.parse import urljoinlink = "https://www.yify-torrent.org/search/1080p/"dirf = os.environ['USERPROFILE'] + '\Desktop\Images'if not os.path.exists(dirf):os.makedirs(dirf)os.chdir(dirf)items = len([name for name in os.listdir(dirf) if os.path.isfile(os.path.join(dirf, name))])if not items: response = requests.get(link) soup = BeautifulSoup(response.text, "lxml") for item in soup.select(".img-item .poster-thumb"): filename = item['src'].split('/')[-1] with open(filename, 'wb') as f: f.write(requests.get(urljoin(link,item['src'])).content)else: print("All images are there")
添加回答
舉報
0/150
提交
取消