Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/692a4e61-621c-8011-95ff-af7aaecbf96d
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{DISPLAYTITLE:画像ダウンロード方法}} ''This conversation was exported from ChatGPT''<ref>{{cite web|title=画像ダウンロード方法|url=https://chatgpt.com/share/692a4e61-621c-8011-95ff-af7aaecbf96d|publisher=ChatGPT|access-date=2025-11-29}}</ref> == gpt-5-mini == === User: https://imgur.com/の画像をダウンロードしたい まずURLリストを用意→画像表示可能か判定→表示可能な画像のみダウンロードしたい === https://imgur.com/の画像をダウンロードしたい まずURLリストを用意→画像表示可能か判定→表示可能な画像のみダウンロードしたい === Assistant: なるほど、やりたいことは以下の手順ですね: === なるほど、やりたいことは以下の手順ですね: # 画像URLリストを用意 # そのURLが実際に画像としてアクセス可能かチェック # アクセス可能な画像のみダウンロード Python でシンプルに実装できます。requests と os を使った例を示します。 <syntaxhighlight lang="python">import requests import os === 画像URLリスト === urls = [ "https://i.imgur.com/XXXXXXX.jpg", "https://i.imgur.com/YYYYYYY.png", ] === 保存先フォルダ === save_folder = "downloaded_images" os.makedirs(save_folder, exist_ok=True) for url in urls: try: # HEADリクエストでアクセス可能かチェック response = requests.head(url, allow_redirects=True) if response.status_code == 200 and 'image' in response.headers.get('Content-Type', ''): # GETリクエストで画像を取得 img_data = requests.get(url).content filename = os.path.join(save_folder, os.path.basename(url)) with open(filename, "wb") as f: f.write(img_data) print(f"Downloaded: {filename}") else: print(f"Not an image or inaccessible: {url}") except Exception as e: print(f"Error accessing {url}: {e}") </syntaxhighlight> ポイント: * HEAD で事前チェックして画像かどうか判定 * ステータスコード 200 かつ Content-Type に "image" が含まれているか確認 * os.path.basename(url) でファイル名を取得 もし希望なら、大量URLでも効率的に並列ダウンロードできるバージョンも作れます。作ってほしいですか? == References == <references /> [[Category:ChatGPT Shares]] [[Category:openai]]
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Cite web
(
edit
)
Module:Citation/CS1
(
edit
)
Module:Citation/CS1/COinS
(
edit
)
Module:Citation/CS1/Configuration
(
edit
)
Module:Citation/CS1/Date validation
(
edit
)
Module:Citation/CS1/Identifiers
(
edit
)
Module:Citation/CS1/Utilities
(
edit
)
Module:Citation/CS1/Whitelist
(
edit
)
Module:Citation/CS1/styles.css
(
edit
)