Код: Выделить всё
links: list[str] # List of Href links, extracted from elements
url: str # URL that these Hrefs came from
urldomain: str # Domain of the URL that these Hrefs came from
for link in links:
if link.startswith('/'):
if link.startswith('//'):
newlinks.append('http://' + link) # HTML
newlinks.append(urldomain + link)
elif link.startswith("http"):
newlinks.append(link)
elif link.startswith("https"):
newlinks.append(link)
if not link.startswith('http'):
if url.endswith('/'):
newlinks.append(url + '/' + link)
else:
newlinks.append('/'.join(url.split('/')[:-1]))
else:
newlinks.append(link)
Подробнее здесь: https://stackoverflow.com/questions/798 ... ref-values
Мобильная версия