Python HTMLParser

How to spent two days if you know nothing about Python: need parse HTML page code, where VK id and username of every person who shared post stores   with open(‘test.html’, ‘r’, encoding=’utf-8′) as content_file: read_data = content_file.read() from html.parser import HTMLParser import re class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): vk_id = str(attrs) for line in vk_id: vk = re.findall(‘/\S+$’, vk_id) vk_fnd = str(vk) if re.search(‘/\w+\’\)\]’, vk_fnd): global vk_read vk_read = vk_fnd for ch in [‘/’, ‘)’, ‘[‘, ‘]’, ‘”‘, “‘”]: if ch in vk_read: vk_read = vk_read.replace(ch, “”) def handle_data(self, data): global vk_name vk_name = str(data) assert isinstance(data, object) for line in vk_name: if re.match(‘\S+\s+\S+$’, vk_name): print(“@{0} – {1}”.format(vk_read, vk_name)) break parser = MyHTMLParser() parser.feed(read_data) Now I know more.Short Read more…