-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_parser.py
More file actions
57 lines (38 loc) · 1.4 KB
/
html_parser.py
File metadata and controls
57 lines (38 loc) · 1.4 KB
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
#Will ask for input of two html files. Will prettify the file and parse it using a regex to find the names.
#Compares the names from the two classes and prints the names that are in both the classes.
import re
from BeautifulSoup import BeautifulSoup
def remove_dup(seq):
Set = set(seq)
return list(Set)
def main():
user = raw_input('Enter your name: ').strip()
html_first = raw_input("Enter the name of the first file: ").strip()
html_second = raw_input("Enter the name of the second file ").strip()
first = open(html_first, 'r')
second = open(html_second, 'r')
soup_first = BeautifulSoup(first.read())
soup_second = BeautifulSoup(second.read())
first.close()
second.close()
output_first = open("output_first.txt", 'w')
output_second = open("output_second.txt", 'w')
output_first.write(soup_first.prettify())
output_second.write(soup_second.prettify())
output_first.close()
output_second.close()
output_first = open("output_first.txt", 'r')
output_second = open("output_second.txt", 'r')
names_first = re.findall('alt="Picture of (.*)" t', output_first.read())
names_second = re.findall('alt="Picture of (.*)" t', output_second.read())
names_first = remove_dup(names_first)
names_second = remove_dup(names_second)
counter = 0
for i in names_first:
for j in names_second:
if i == j:
if i.lower() != user.lower():
counter = counter + 1
print(j)
print(counter)
main()