Skip to content Skip to sidebar Skip to footer

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 methodsclassMyHTMLParser(HTMLParser):
    defhandle_starttag(self, tag, attrs):
        print"Encountered a start tag:", tag
    defhandle_endtag(self, tag):
        print"Encountered an end tag :", tag
    defhandle_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"