1 #!/usr/bin/env python 2 import urllib 3 from HTMLParser import HTMLParser 4 5 class GetMyCode(HTMLParser): 6 current_start_tag = "" 7 ip_txt = "" 8 9 def handle_starttag(self, tag, attrs): 10 self.current_start_tag = tag 11 12 def handle_data(self, data): 13 if self.current_start_tag == "title": 14 ip_txt = data 15 16 17 parser = GetMyCode() 18 file = open("test.html",'r') 19 20 parser.feed(file.read()) 21 parser.close() 22 file.close() 23 24 print parser.ip_txt