开发者

When download an image, does urllib have a return code if it's successful or not?

开发者 https://www.devze.com 2023-01-09 04:16 出处:网络
I want to download an image file from potentially 5 sites. Meaning that if the image wasn\'t found in site#1, try 开发者_StackOverflow中文版site#2, etc.

I want to download an image file from potentially 5 sites.

Meaning that if the image wasn't found in site#1, try 开发者_StackOverflow中文版site#2, etc.

How can I test if the file was downloaded?


You can call getcode() on the object you get back from urlopen().

getcode() gives you the HTTP status response from the server, so you can test to see if you got an HTTP 200 response, which would mean the download was successful.

0

精彩评论

暂无评论...
验证码 换一张
取 消