-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.py
347 lines (250 loc) · 6.34 KB
/
features.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
"""
from bs4 import BeautifulSoup
with open("mini_dataset/6.html") as f:
test = f.read()
soup = BeautifulSoup(test, "html.parser")
"""
# has_title
def has_title(soup):
if soup.title is None:
return 0
if len(soup.title.text) > 0:
return 1
else:
return 0
# has_input
def has_input(soup):
if len(soup.find_all("input")):
return 1
else:
return 0
# has_button
def has_button(soup):
if len(soup.find_all("button")) > 0:
return 1
else:
return 0
# has_image
def has_image(soup):
if len(soup.find_all("image")) == 0:
return 0
else:
return 1
# has_submit
def has_submit(soup):
for button in soup.find_all("input"):
if button.get("type") == "submit":
return 1
else:
pass
return 0
# has_link
def has_link(soup):
if len(soup.find_all("link")) > 0:
return 1
else:
return 0
# has_password
def has_password(soup):
for input in soup.find_all("input"):
if (input.get("type") or input.get("name") or input.get("id")) == "password":
return 1
else:
pass
return 0
# has_email_input
def has_email_input(soup):
for input in soup.find_all("input"):
if (input.get("type") or input.get("id") or input.get("name")) == "email":
return 1
else:
pass
return 0
# has_hidden_element
def has_hidden_element(soup):
for input in soup.find_all("input"):
if input.get("type") == "hidden":
return 1
else:
pass
return 0
# has_audio
def has_audio(soup):
if len(soup.find_all("audio")) > 0:
return 1
else:
return 0
# has_video
def has_video(soup):
if len(soup.find_all("video")) > 0:
return 1
else:
return 0
# number_of_inputs
def number_of_inputs(soup):
return len(soup.find_all("input"))
# number_of_buttons
def number_of_buttons(soup):
return len(soup.find_all("button"))
# number_of_images
def number_of_images(soup):
image_tags = len(soup.find_all("image"))
count = 0
for meta in soup.find_all("meta"):
if meta.get("type") or meta.get("name") == "image":
count += 1
return image_tags + count
# number_of_option
def number_of_option(soup):
return len(soup.find_all("option"))
# number_of_list
def number_of_list(soup):
return len(soup.find_all("li"))
# number_of_TH
def number_of_TH(soup):
return len(soup.find_all("th"))
# number_of_TR
def number_of_TR(soup):
return len(soup.find_all("tr"))
# number_of_href
def number_of_href(soup):
count = 0
for link in soup.find_all("link"):
if link.get("href"):
count += 1
return count
# number_of_paragraph
def number_of_paragraph(soup):
return len(soup.find_all("p"))
# number_of_script
def number_of_script(soup):
return len(soup.find_all("script"))
# length_of_title
def length_of_title(soup):
if soup.title == None:
return 0
return len(soup.title.text)
"""
print("has_title --> ", has_title(soup))
print("has_input --> ", has_input(soup))
print("has_button --> ", has_button(soup))
print("has_image --> ", has_image(soup))
print("has_submit --> ", has_submit(soup))
print("has_link --> ", has_link(soup))
print("has_password --> ", has_password(soup))
print("has_email_input --> ", has_email_input(soup))
print("has_hidden_element --> ", has_hidden_element(soup))
print("has_audio --> ", has_audio(soup))
print("has_video --> ", has_video(soup))
print("number_of_inputs --> ", number_of_inputs(soup))
print("number_of_buttons --> ", number_of_buttons(soup))
print("number_of_images --> ", number_of_images(soup))
print("number_of_option --> ", number_of_option(soup))
print("number_of_list --> ", number_of_list(soup))
print("number_of_TH --> ", number_of_TH(soup))
print("number_of_TR --> ", number_of_TR(soup))
print("number_of_href --> ", number_of_href(soup))
print("number_of_paragraph --> ", number_of_paragraph(soup))
print("number_of_script --> ", number_of_script(soup))
print("length_of_title --> ", length_of_title(soup))
"""
# has h1
def has_h1(soup):
if len(soup.find_all("h1")) > 0:
return 1
else:
return 0
# has h2
def has_h2(soup):
if len(soup.find_all("h2")) > 0:
return 1
else:
return 0
# has h3
def has_h3(soup):
if len(soup.find_all("h3")) > 0:
return 1
else:
return 0
# length of text
def length_of_text(soup):
return len(soup.get_text())
# number of clickable button
def number_of_clickable_button(soup):
count = 0
for button in soup.find_all("button"):
if button.get("type") == "button":
count += 1
return count
# number of a
def number_of_a(soup):
return len(soup.find_all("a"))
# number of img
def number_of_img(soup):
return len(soup.find_all("img"))
# number of div class
def number_of_div(soup):
return len(soup.find_all("div"))
# number of figures
def number_of_figure(soup):
return len(soup.find_all("figure"))
# has footer
def has_footer(soup):
if len(soup.find_all("footer")) > 0:
return 1
else:
return 0
# has form
def has_form(soup):
if len(soup.find_all("form")) > 0:
return 1
else:
return 0
# has textarea
def has_text_area(soup):
if len(soup.find_all("textarea")) > 0:
return 1
else:
return 0
# has iframe
def has_iframe(soup):
if len(soup.find_all("iframe")) > 0:
return 1
else:
return 0
# has text input
def has_text_input(soup):
for input in soup.find_all("input"):
if input.get("type") == "text":
return 1
return 0
# number of meta
def number_of_meta(soup):
return len(soup.find_all("meta"))
# has nav
def has_nav(soup):
if len(soup.find_all("nav")) > 0:
return 1
else:
return 0
# has object
def has_object(soup):
if len(soup.find_all("object")) > 0:
return 1
else:
return 0
# has picture
def has_picture(soup):
if len(soup.find_all("picture")) > 0:
return 1
else:
return 0
# number of sources
def number_of_sources(soup):
return len(soup.find_all("source"))
# number of span
def number_of_span(soup):
return len(soup.find_all("span"))
# number of table
def number_of_table(soup):
return len(soup.find_all("table"))