Skip to content

Instantly share code, notes, and snippets.

@studiawan
Created December 16, 2013 05:15
Show Gist options
  • Save studiawan/7982630 to your computer and use it in GitHub Desktop.
Save studiawan/7982630 to your computer and use it in GitHub Desktop.
HTTP client using urllib2 and native HTMLParser
from HTMLParser import HTMLParser
import urllib2
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print "Encountered a start tag:", tag
def handle_endtag(self, tag):
print "Encountered an end tag :", tag
def handle_data(self, data):
print "Encountered some data :", data
parser = MyHTMLParser()
response = urllib2.urlopen('http://www.studiawan.com').read()
parser.feed(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment