开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜