johnmahugu

python - get all links in a website 1

Jun 14th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. Get all links in a web page (1)
  2.  
  3. ... or regular expression marvels.
  4. import re, urllib
  5. htmlSource = urllib.urlopen("http://learn.pythonanywhere.com").read(200000)
  6. linksList = re.findall('<a href=(.*?)>.*?</a>',htmlSource)
  7. for link in linksList:
  8. print link
Advertisement
Add Comment
Please, Sign In to add comment