亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果其中一些圖像已經在文件夾中,則無法讓我的腳本下載其余圖像

如果其中一些圖像已經在文件夾中,則無法讓我的腳本下載其余圖像

30秒到達戰場 2021-11-02 16:19:44
我在 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")
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號