-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment_Finder.py
62 lines (52 loc) · 2.24 KB
/
Comment_Finder.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
from bs4 import BeautifulSoup
from bs4 import Comment
import requests
import argparse
"""
A simple python code to find commentlines on a webpage
requirements --> bs4, lxml
For install required libraries run this command: pip install bs4 lxml
"""
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", help="Write founded comments to an output file", required=False)
parser.add_argument("-t", "--target", help="Webiste address to find comments inside its code", required=True)
args = parser.parse_args()
codename = """
_ _____ ____ ____ _ ____ ____
| |/ / _ \| _ \ _ | _ \ / \ | _ \/ ___|
| ' / | | | | | (_) | |_) / _ \ | |_) \___ \
| . \ |_| | |_| |_ | __/ ___ \| _ < ___) |
|_|\_\___/|____/(_) |_| /_/ \_\_| \_\____/
"""
finder = """
____ _ _____ _ _
/ ___|___ _ __ ___ _ __ ___ ___ _ __ | |_ | ___(_)_ __ __| | ___ _ __
| | / _ \| '_ ` _ \| '_ ` _ \ / _ \ '_ \| __| | |_ | | '_ \ / _` |/ _ \| '__|
| |__| (_) | | | | | | | | | | | __/ | | | |_ | _| | | | | | (_| | __/| |
\____\___/|_| |_| |_|_| |_| |_|\___|_| |_|\__| |_| |_|_| |_|\__,_|\___||_|
\n\n"""
print(codename)
print(finder)
print("\nSearching comments on website: ", args.target)
resp = requests.get(args.target)
data = resp.text
sp = BeautifulSoup(data, "lxml")
comments = list(sp.findAll(text = lambda text: isinstance(text, Comment)))
for i,j in enumerate(comments):
if j.replace(" ", "") == "":
comments.pop(i)
if args.output != None:
with open(args.output, "w") as f:
for i in comments:
if i.replace(" ", "") == "":
continue
res = "*"*25 + "COMMENT STARTS" + "*"*23 + "\n" + i + "\n" + "*"*25 + "COMMENT ENDS" + "*"*25 + "\n"
f.writelines(res)
print("Results have been written to file: ", args.output)
else:
for i in comments:
if i.replace(" ", "") == "":
continue
res = "*"*25 + "COMMENT STARTS" + "*"*23 + "\n" + i + "\n" + "*"*25 + "COMMENT ENDS" + "*"*25 + "\n"
print(res)
print(str(len(comments)), " comments have founded!")