-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1121.py
More file actions
37 lines (29 loc) · 1.02 KB
/
1121.py
File metadata and controls
37 lines (29 loc) · 1.02 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from html.parser import HTMLParser
from html.entities import name2codepoint
class MyHTMLParser(HTMLParser):
def __init__(self):
super(MyHTMLParser, self).__init__()
self._flag = ''
def handle_starttag(self, tag, attrs):
if ('class','event-title') in attrs:
self._flag = 'event-title:'
elif ('class','event-location') in attrs:
self._flag = 'event-location:'
elif tag == 'time':
self._flag = 0
def handle_data(self,data):
if self._flag in ('event-title:','event-location:'):
if self._flag == 'event-title:':
print ('-'*35)
print (self._flag,data.strip())
self._flag = ' '
if isinstance(self._flag,int):
l = ['-',',','\n']
if self._flag<3:
print(data.strip(),end = l[self._flag])
self._flag +=1
parser = MyHTMLParser()
with open('index.html') as html:
parser.feed(html.read())