I'm practicing Python crawl.
Originally, when you get the uploaded image address on the site, the Internet Explorer opens and the image opens Using this, I changed the urllib.request image URL to the desired file name and downloaded it.
But one site doesn't open on the web when I click on the image URL, but it automatically downloads...
Don't try to save the URL by doing urllib.request to change it to the file name you want.
If I click the URL, it will be saved automatically, so is there a way to open it on the web and change the image name to the name you want and save it?
Thank you.
python-3.x
I called the header using the requests for the address you uploaded, and the content-type was as follows.
'Content-Type': 'application/octet-stream'
For example, the address of the profile picture you are using is 'image/jpeg'.
https://res.cloudinary.com/eightcruz/image/facebook/c_lfill,h_32,w_32/3277655915597638
'Content-Type': 'image/jpeg'
This data is called a MIME type, which means in what form it will be delivered to the client. The browser can read the MIME type, determine what data it is, and decide whether to display it in the browser or download it.
'application/octet-stream' did not open in the browser because it means all kinds of binary data.
The header information is determined by the server side.
It would be better to search for more information by searching for the MIME type.
How about saving it to the file name you want, in the following way? If the extension is different, you can parse it separately and attach it.
import requests
req0 = requests.get('https://mall-image.tving.com/media/file/goods/2020/07/50a101706b3e69dec13b9ddb69aa9442.jpg')
file = open("yes.jpg",mode="wb")
file.write(req0.content)
file.close()
# Below is the header reference code.
print(req0.headers)
req1 = requests.get('https://res.cloudinary.com/eightcruz/image/facebook/c_lfill,h_32,w_32/3277655915597638')
print(req1.headers)
Thank you.
© 2024 OneMinuteCode. All rights reserved.