Created
December 12, 2021 04:15
-
-
Save Neko288/a5fdc774a1854b75feeefb65d5a0e44e to your computer and use it in GitHub Desktop.
サイトの画像を全部DL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, winsound | |
from bs4 import BeautifulSoup | |
import os | |
#画像のURL構造がサイトによって異なるので、エラーが起きたら微修正お願いします。よくあるエラーは24行目当たりのrequests.getです。 | |
path = ('C:/保存する画像のパス') | |
def save_image(): | |
URL = ('http://XXXX') | |
try: | |
os.mkdir("img") | |
except: | |
pass | |
soup = BeautifulSoup(requests.get(URL).content,'lxml') | |
imgs = [] | |
for link in soup.find_all("img"): | |
if link.get("src").endswith(".jpg"): | |
imgs.append(link.get("src")) | |
elif link.get("src").endswith(".png"): | |
imgs.append(link.get("src")) | |
elif link.get("src").endswith(".webp"): | |
imgs.append(link.get("src")) | |
for target in imgs: | |
re = requests.get('http://'+target) | |
with open(path+'/'+''+target.split('/')[-1], 'wb') as f: | |
f.write(re.content) | |
print("オワタヨ"+'\n') | |
winsound.Beep(294,1000) | |
while True: | |
save_image() | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment