Python urllib cache
问题 I'm writing a script in Python that should determine if it has internet access. import urllib CHECK_PAGE = "http://64.37.51.146/check.txt" CHECK_VALUE = "true\n" PROXY_VALUE = "Privoxy" OFFLINE_VALUE = "" page = urllib.urlopen(CHECK_PAGE) response = page.read() page.close() if response.find(PROXY_VALUE) != -1: urllib.getproxies = lambda x = None: {} page = urllib.urlopen(CHECK_PAGE) response = page.read() page.close() if response != CHECK_VALUE: print "'" + response + "' != '" + CHECK_VALUE +