Найти - Пользователи
Полная версия: Вырезать доменное имя из ссылки
Начало » Python для новичков » Вырезать доменное имя из ссылки
1
py.webs
Как грамотно достать домен второго, третьего уровня из любой ссылки?
cutwater
import urlparse
py.webs
Еще такая проблема. urlparse не режет www. у доменов.
Как лучше обрезать?
minotavr_x86
s = 'www.ya.ru.com'
import re
domain_re = re.compile(r'(?:www\.)*((?:[\w]+\.)+\w+)/*')
print domain_re.findall(s)
или
s = 'www.ya.ru.com'
if s[:3].lower() == 'www':
s = s[4:]
Singularitty
>>> httplib.urlsplit("http://python.su/forum/viewtopic.php?id=13469")
SplitResult(scheme='http', netloc='python.su', path='/forum/viewtopic.php', query='id=13469', fragment='')
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB