All pastes #186954 Raw Edit

rvsjoen

public python v1 · immutable
#186954 ·published 2006-09-30 17:34 UTC
rendered paste body
  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 = "ting"  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                         GetMyCode.ip_txt = data 15 16 17 parser = GetMyCode() 18 file = open("whatismyip.html",'r') 19 #file = urllib.urlopen("http://www.whatismyip.com") 20 parser.feed(file.read()) 21 parser.close() 22 file.close() 23 print parser.ip_txt