-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlparser.py
executable file
·100 lines (82 loc) · 3.63 KB
/
htmlparser.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
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
__description__ = "This tool is used to analyze the source code of an html page by recovering tags and comments"
__version__ = "1.5.0"
__author__ = "Anataar"
try:
import optparse
from scripts import MakeTree, Parser, Request
except ModuleNotFoundError as Error:
print(Error)
def Main():
## Menu options
Menu = optparse.OptionParser(usage='python %prog [options] <url>', version='%prog ' + __version__)
Menu.add_option("-a", "--all", action="store_true",dest="all", help="Parse with all options (-c, -s, -f, -l)")
Menu.add_option("-c", "--comment", action="store_true",dest="comment", help="Find all comments")
Menu.add_option("-s", "--script", action="store_true",dest="script", help="Find all scripts")
Menu.add_option("-f", "--form", action="store_true",dest="form", help="Find all forms")
Menu.add_option("-l", "--link", action="store_true",dest="link", help="Find all links")
Menu.add_option("-t", "--tree", action="store_true",dest="tree", help="Make a tree of the website directories")
(options, args) = Menu.parse_args()
Examples = optparse.OptionGroup(Menu, "Examples", """python htmlparser.py -a <url>
python htmlparser.py -c <url>
python htmlparser.py -s <url>
python htmlparser.py -f <url>
python htmlparser.py -l <url>
python htmlparser.py -t <url>
""")
Menu.add_option_group(Examples)
## For wrong or none arguments
if len(args) == 0 or options == {'all':None, 'comment':None, 'script':None, 'form':None, 'link':None, 'tree':None}:
Menu.print_help()
print("\n" +__description__)
## --all option
if options.all == True and len(args) != 0 and len(args) < 2:
Parser.parse_all(Request.GET_request(args[0]))
elif options.all == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.all == True and len(args) == 0:
print("\nNo url detected !")
## --comment option
if options.comment == True and len(args) != 0 and len(args) < 2:
Parser.parse_comment(Request.GET_request(args[0]))
elif options.comment == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.comment == True and len(args) == 0:
print("\nNo url detected !")
## --script option
if options.script == True and len(args) != 0 and len(args) < 2:
Parser.parse_script(Request.GET_request(args[0]))
elif options.script == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.script == True and len(args) == 0:
print("\nNo url detected !")
## --form option
if options.form == True and len(args) != 0 and len(args) < 2:
Parser.parse_form(Request.GET_request(args[0]))
elif options.form == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.form == True and len(args) == 0:
print("\nNo url detected !")
## --link option
if options.link == True and len(args) != 0 and len(args) < 2:
Parser.parse_link(Request.GET_request(args[0]), False)
elif options.link == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.link == True and len(args) == 0:
print("\nNo url detected !")
## --tree option
if options.tree == True and len(args) != 0 and len(args) < 2:
#parse_link(GET_request(args[0]))
tree = MakeTree.URLTree(args[0], Parser.parse_link(Request.GET_request(args[0]), True))
tree.generate()
elif options.tree == True and len(args) > 1:
print("\nError: too many argmuments !")
elif options.tree == True and len(args) == 0:
print("\nNo url detected !")
if __name__ == "__main__":
try:
Main()
except KeyboardInterrupt:
print()
print("Aborting...")
print()