Parse hyperlinks in webpage using python

import urllib, htmllib, formatter
 
website = urllib.urlopen("http://w3mentor.com")
data = website.read()
website.close()
format = formatter.AbstractFormatter(formatter.NullWriter())
ptext = htmllib.HTMLParser(format)
ptext.feed(data)
for link in ptext.anchorlist:
   print(link)

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.