-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlsniffer.py
87 lines (54 loc) · 2.09 KB
/
htmlsniffer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# trying to get htmlcodesniffer to run via python
#
#
#
#
import os
import sys
import getopt
import time
from os import walk
from selenium import webdriver
checker = 'lib/codesniffer/HTMLCS.js'
runner = 'lib/codesniffer/Contrib/PhantomJS/runner.js'
standard = 'lib/codesniffer/standards/WCAG2AA/ruleset.js'
standards_folder = 'lib/codesniffer/standards'
class htmlChecker(object):
def __init__(self):
self.dir = os.path.dirname(__file__)
phantompath = os.path.join(self.dir, 'lib/phantomjs/bin/phantomjs')
self.driver = webdriver.PhantomJS(executable_path='lib/phantomjs/bin/phantomjs')
def page(self, url):
print 'checking', url
self.driver.set_window_size(1280, 1024)
self.driver.get(url)
#print 'waiting....'
#time.sleep(5)
javaScript = ''
javaScript += self.loadStandards(standards_folder);
javaScript += self.getScript(checker)
javaScript += self.getScript(runner)
javaScript += self.getScript('sniffer/loader.js')
print "loaded javascript: ", len(javaScript)
result = self.driver.execute_script(javaScript)
print 'Result: ', result
time.sleep(2)
logs = self.driver.get_log("browser");
for log in logs:
print "ConsoleLog:", log['message']
def getScript(self, script):
with open(os.path.join(self.dir, script), 'r') as file:
return file.read()
def loadStandards(self, folder):
standardsScript = ""
fullpath = os.path.join(self.dir, folder)
for(dirpath, dirnames, filenames) in walk(fullpath):
for file in filenames:
standardsScript += self.getScript(os.path.join(dirpath, file))
return standardsScript
def main(argv):
check = htmlChecker()
check.page('http://jumoo.uk')
if __name__ == '__main__':
main(sys.argv[1:])