lolamontes69

Python/ Get some links from an Url

May 19th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. import urllib2
  2. import re
  3. #connect to a URL
  4. url = raw_input('Enter url > ')
  5. website = urllib2.urlopen(url)
  6.  
  7. #read html code
  8. html = website.read()
  9.  
  10. #use re.findall to get all the links
  11. links = re.findall('"((http|ftp)s?://.*?)"', html)
  12. for a in links:
  13.     if ("htm" in a[0]) and ('dtd' not in a[0]) and ('xhtml' not in a[0]):
  14.         print a[0]
Advertisement
Add Comment
Please, Sign In to add comment