# 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://udacity.com">') start_link = page.find('<a href=') #print start_link #print page[89:] first_marker = page.find('"',start_link)+1 #print page.find('"',start_link) second_marker = page.find('"',first_marker+1) #print page.find('"',first_marker+1) #print page[first_marker:second_marker] url = page[first_marker:second_marker] print url
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question