我当前的代码是
#imports
import requests
#setup
response = requests.get("https://randomfox.ca/floof/")
fox = response.json()
#code
print(fox['image'])
每当我运行它时,它总是打印类似 https://randomfox.ca/images/99.jpg 的内容。 有什么办法可以改变它并使其变成 99.jpg 吗?
import requests
import os
# Setup
response = requests.get("https://randomfox.ca/floof/")
fox = response.json()
# Extract the filename
image_url = fox['image']
filename = os.path.basename(image_url)
# Codeprint(filename)