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 urllib.request
import tempfile
import os
import webbrowser
import time
url = "https://www.aomori-ringo.or.jp/kids/wp-content/uploads/2021/11/apple.png"
try:
with urllib.request.urlopen(url) as response:
img_data = response.read()
# 一時ファイルに保存して表示
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp:
tmp.write(img_data)
print(f"file://{tmp.name}")
webbrowser.open(f"file://{tmp.name}")
time.sleep(3)
except Exception as e:
print(f"エラーが発生しました: {e}")
finally:
if 'tmp' in locals():
os.unlink(tmp.name) # 一時ファイル削除
|