# Modify the get_next_target procedure so that # if there is a link it behaves as before, but # if there is no link tag in the input string, # it returns None, 0. # Note that None is not a string and so should # not be enclosed in quotes. # Also note that your answer will appear in # parentheses if you print it. page = '3gewlkf <a href="http:udacity.com" 3tjfekljad <a href="http:wawa.com">fdagae' #this bit tests whether there is a link or not. If there is a link it outputs url string, and end_quote position #if no links then outputs None condition def get_next_target(page): start_link = page.find('<a href=') if start_link == -1: return None, 0 start_quote = page.find('"', start_link) end_quote = page.find('"', start_quote + 1) url = page[start_quote + 1:end_quote] return url, end_quote #this bit sets the condition to go back to get_next_target until result gives None condition, in which case it breaks. def print_all_links(page): while True: url, endpos = get_next_target(page) if url: print url page = page[endpos:] else: break print_all_links(page)
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