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:\n\n" % (size, url) print code size += 1code 中以 url“http://lh6.ggpht.com/_Eyd_-h7bEhI/SaX5Ys8m02I/AAAAAAAAIj0/JA5TPeK7APc/s???/locater.jpg”为例,替换该 url 中的“???”为 size 即是各个 size 图片的 url。该图原始尺寸是 1279×1022,原始图片 url 为(没有“s???”路径):
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:
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:
没有评论 :
发表评论