-
Notifications
You must be signed in to change notification settings - Fork 0
/
L02.py
47 lines (36 loc) · 997 Bytes
/
L02.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
# http://www.pythonchallenge.com/pc/def/equality.html
import urllib.request
import re
from collections import Counter
def get_html_page(url):
page = None
resp = urllib.request.urlopen(url)
if (resp.status == 200):
page = resp.read().decode('utf-8')
return page
def get_comments(page):
rs = re.findall('<!--\s*(.*?)\s*-->', page, re.S)
print(rs)
if rs:
return rs[1]
return None
"""
def main():
url = 'http://www.pythonchallenge.com/pc/def/ocr.html'
page = get_html_page(url)
comments = get_comments(page)
print(comments)
maps = {}
for c in comments:
maps[c] = maps.get(c, 0) + 1
half = len(comments) // len(maps)
rs = ""
for k, v in maps.items():
if v < half:
rs += k
print(rs)
main()"""
url = 'http://www.pythonchallenge.com/pc/def/ocr.html'
page = get_html_page(url)
comments = get_comments(page)
print(Counter(comments))