Skip to content

Instantly share code, notes, and snippets.

@mozillazg
Created September 5, 2012 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozillazg/3637230 to your computer and use it in GitHub Desktop.
Save mozillazg/3637230 to your computer and use it in GitHub Desktop.
cs101-unit1
# Write Python code that assigns to the
# variable url a string that is the value
# of the first URL that appears in a link
# tag in the string page.
# page = contents of a web page
page =('<div id="top_bin"><div id="top_content" class="width960">'
'<div class="udacity float-left"><a href="http://www.xkcd.com">')
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote + 1)
url = page[start_quote+1:end_quote]
print url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment