Python HTML Parsing From Url
I've heard it's possible to get data from a link. But I want to know the best method, I've read about that, but I still want to know how and what's the best module to do so. I want
Solution 1:
From Python HTMLParser Documentation:
from HTMLParser import HTMLParser
# create a subclass and override the handler methods
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
# instantiate the parser and fed it some HTML
parser = MyHTMLParser()
parser.feed('<html><head><title>Test</title></head>'
'<body><h1>Parse me!</h1></body></html>')
In your case you can just use the handle_data
function to print HTML contents.
Post a Comment for "Python HTML Parsing From Url"