import httplib, urlparse def http_exists(url): host, path = urlparse.urlsplit(url)[1:3] if ':' in host: # port specified, try to use it host, port = host.split(':', 1) try: port = int(port) except ValueError: print 'invalid port number %r' % (port,) return False else: # no port specified, use default port port = None try: connection = httplib.HTTPConnection(host, port=port) connection.request("HEAD", path) resp = connection.getresponse( ) if resp.status == 200: # normal 'found' status found = True elif resp.status == 302: # recurse on temporary redirect found = httpExists(urlparse.urljoin(url, resp.getheader('location', ''))) else: # everything else -> not found # print "Status %d %s : %s" % (resp.status, resp.reason, url) found = False except Exception, e: print e.__class__, e, url found = False connection.close() return found if __name__ == '__main__': size = 1 while size < 10000: url = 'http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s%d/locater.jpg' % size # print url if http_exists(url): code = "s%d:\ncode 中以 url“http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s???/locater.jpg”为例,替换该 url 中的“???”为 size 即是各个 size 图片的 url。该图原始尺寸是 1279×1022,原始图片 url 为(没有“s???”路径):\n" % (size, url) print code size += 1
http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/locater.jpg"上面的代码输出有效尺寸图片的 HTML script,验证下来尺寸有:
s32、s48、s64、s72、s94、s104、s110、s128、s144、s150、s160、s200、s220、s288、s320、s400、s512、s576、s640、s720、s800、s912、s1024、s1152、s1280、s1440、s1600图片预览效果如下:
s32:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s32/locater.jpg)
s48:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s48/locater.jpg)
s64:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s64/locater.jpg)
s72:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s72/locater.jpg)
s94:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s94/locater.jpg)
s104:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s104/locater.jpg)
s110:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s110/locater.jpg)
s128:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s128/locater.jpg)
s144:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s144/locater.jpg)
s150:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s150/locater.jpg)
s160:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s160/locater.jpg)
s200:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s200/locater.jpg)
s220:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s220/locater.jpg)
s288:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s288/locater.jpg)
s320:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s320/locater.jpg)
s400:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s400/locater.jpg)
s512:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s512/locater.jpg)
s576:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s576/locater.jpg)
s640:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s640/locater.jpg)
s720:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s720/locater.jpg)
s800:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s800/locater.jpg)
s912:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s912/locater.jpg)
s1024:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s1024/locater.jpg)
s1152:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s1152/locater.jpg)
s1280:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s1280/locater.jpg)
s1440:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s1440/locater.jpg)
s1600:
![](http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s1600/locater.jpg)
没有评论 :
发表评论