सभी यूआरएल मुद्रित करें - पायथन - पायथन, यूआरएल, हाइपरलिंक

I already created a get_url function that retrieves one url, I am now trying to call that function to define a different one, print_all_links(s), that prints all urls from an inputted string. This is what I have so far, it prints the correct amount of url"s but they are just the first url repeated, and not on one line, please help

def get_url(s):
#s = s.replace(" ", "")
b = s.find("<a href=")
if b != -1:
return s[b + 9 : b + 9 + s[b + 9::].find(""")]
else:
return b

#prints all URls in HTML input
def print_all_links(s):
i = s.count("<a href=")
n = i
x = ""
while n > 0:
x += get_url(s)
print(x)
s = s.replace(x, "")
n = n-1

नमूना इनपुट: print_all_links ( " शिकागो में इलिनोइस विश्वविद्यालय |

प्रिंट: https://uic.edu https://uic.edu

उत्तर:

जवाब के लिए 0 № 1

इसे इस्तेमाल करे

def get_url(s):
#s = s.replace(" ", "")
b = s.find("<a href=")
if b != -1:
return s[b + 9 : b + 9 + s[b + 9::].find(""")]
else:
return b

#prints all URls in HTML input
def print_all_links(s):
i = s.count("<a href=")
print(i)
n = i
x = ""
while n > 0:
x = get_url(s)
print(x)
s = s.replace("<a href="" + x, "")
n = n-1

संबंधित सवाल
सबसे लोकप्रिय