fork download
  1. print ""
  2. print "CS101 unit2-30"
  3. print "Print all the links on a page"
  4. print "- Solution: https://w...content-available-to-author-only...y.com/course/viewer#!/c-cs101/l-48753036/e-48727558/m-48683657"
  5.  
  6. print "My forum posts regarding this"
  7. print "http://p...content-available-to-author-only...m.org/viewtopic.php?f=6&t=2699"
  8. print "https://f...content-available-to-author-only...y.com/questions/100051898/help-me-debug-typeerror-unpack-non-sequence#cs101"
  9.  
  10. def print_all_links(page):
  11. while True:
  12. url, end_quote = get_next_target(page)
  13. if url:
  14. print url
  15. page = page[end_quote:]
  16. else:
  17. break
  18.  
  19. def get_next_target(page):
  20. start_link = page.find('<a href=')
  21. start_quote = page.find('"', start_link)
  22. #http = page.find('http', start_link)
  23. #www = page.find('www', start_link)
  24. end_quote = page.find('"', start_quote + 1)
  25. url = page[start_quote + 1: end_quote]
  26. return url, end_quote
  27.  
  28. print "Test #1, Multiple Links"
  29. print_all_links('this is a <a href="http://l...content-available-to-author-only...1.com">link</a>, this is a <a href="http://l...content-available-to-author-only...2.com">link</a>, this is a <a href="http://l...content-available-to-author-only...3.com">link</a>')
  30.  
  31.  
Success #stdin #stdout 0.09s 8648KB
stdin
Standard input is empty
stdout
CS101 unit2-30
Print all the links on a page
- Solution: https://w...content-available-to-author-only...y.com/course/viewer#!/c-cs101/l-48753036/e-48727558/m-48683657
My forum posts regarding this
http://p...content-available-to-author-only...m.org/viewtopic.php?f=6&t=2699
https://f...content-available-to-author-only...y.com/questions/100051898/help-me-debug-typeerror-unpack-non-sequence#cs101
Test #1, Multiple Links
http://l...content-available-to-author-only...1.com
http://l...content-available-to-author-only...2.com
http://l...content-available-to-author-only...3.com