Get all links from a website


/ Published in: Python
Save to your folder(s)

Get all links from a website
from: http://www.pythonforbeginners.com/code/regular-expression-re-findall


Copy this code and paste it in your HTML
  1. import urllib2
  2. import re
  3.  
  4. #connect to a 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.  
  13. print links

URL: http://www.pythonforbeginners.com/code/regular-expression-re-findall

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.