Python. Извлечение url со страницы

Этот код анализирует страницу и извлекает URL-адрес для создания карты сайта. Вместе с url забирает и часть кода js. Как сделать так чтобы исключить js?

if (resp.status == 200 and
        ('text/html' in resp.headers.get('content-type'))):
    data = (await resp.read()).decode('utf-8', 'replace')
    urls = re.findall(r'(?i)href=["\']?([^\s"\'<>]+)', data)
    asyncio.Task(self.addurls([(u, url) for u in urls])

Получаются ссылки:

http://google.com

http://google.com/intl/ru/policies/terms/

http://google.com/intl/ru/policies/privacy/

http://google.com/intl/ru/policies/terms/url}}catch(e){}if(window.location.hash)url+=window.location.hash;window.location.href=url;

http://google.com/preferences?hl=ru

http://google.com/intl/ru/policies/privacy/url}}catch(e){}if(window.location.hash)url+=window.location.hash;window.location.href=url;

http://google.com/f},0)};}).call(this);


Ответы (1 шт):

Автор решения: vanesicks

Добавьте закрывающую кавычку к вашей регулярке

re.findall(r'(?i)href=["\']?([^\s"\'<>]+)["\']', data)
→ Ссылка