From 4865e04986a6e6b861c8d0abd22cc7a83519fa2e Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 22 May 2017 01:55:37 +1000 Subject: [PATCH] Got the starttag working as a global variable --- HTTPy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/HTTPy.py b/HTTPy.py index 5cfb087..6c1ed81 100755 --- a/HTTPy.py +++ b/HTTPy.py @@ -6,8 +6,14 @@ starttag = "" class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): + global starttag starttag = tag - print starttag + #print starttag + def handle_data(self, data): + #print starttag + if starttag == "code": + print data + pass conn = httplib.HTTPSConnection("www.python.org") @@ -15,4 +21,4 @@ conn.request("GET", "/") r1 = conn.getresponse() parser = MyHTMLParser() -parser.feed(r1.read()) +parser.feed(r1.read()) \ No newline at end of file