# Validation Type vtype = 'HTML' # Specify a file path for storing results pt = '../target/' # Create a filename to store the results in fn = 'Results_' + vtype + '_' + time.strftime('%m%d%y_%H%M%S') + '.txt' # Create validator object vld = HTMLValidator() # Validate URL vld.validate(url) # Capture validator errors e = vld.errors # Capture validator warnings w = vld.warnings # Create a line separator sep = ''.join(['=']*80) # Output the results res = '' res = ''.join([res,sep]) res = '\n'.join([res,'W3C VALIDATOR RESULTS']) res = '\n'.join([res,sep])
reader = csv.reader(f) csv_hash = {rows[0]: rows[1] for rows in reader} for lib_name, url in csv_hash.items(): try: url = url.replace(" ", "") lib_name = lib_name.replace(" ", "_") # Create folder for your current library's data print "Creating folder for " + lib_name subdirectory = lib_name dir_path = "./" + directory + "/" + subdirectory if not os.path.exists(dir_path): os.makedirs(dir_path) # W3C Query/Response vld = HTMLValidator() vld.validate(url) w3c_warnings = convert(vld.warnings) save(w3c_warnings, 'w3c_warnings', lib_name, directory, subdirectory) w3c_errors = convert(vld.errors) save(w3c_errors, 'w3c_errors', lib_name, directory, subdirectory) w3c_warnings = solrize_w3c(w3c_warnings, "w3c_warnings") w3c_errors = solrize_w3c(w3c_errors, "w3c_errors") w3c = dict(w3c_warnings, **w3c_errors) w3c = flatten(w3c) time.sleep(1)
import sys import time from py_w3c.validators.html.validator import HTMLValidator with open('CNAME', 'r') as f: cname = f.readline().splitlines()[0] vld = HTMLValidator() vld.validate("http://%s/" % cname) if len(vld.errors) > 0: for error in vld.errors: print "#%s: %s" % (error['line'], error['message']) sys.exit(1) print '' print 'W3C validation passed'
def validate(self): vld = HTMLValidator() vld.validate(self.url) self.result.w3c = vld.errors