You can use built-in xml.etree.ElementTree instead: >>> import xml.etree.ElementTree as ET >>> url=”<a rel=”nofollow” href=”https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip”>XYZ</a>” >>> ET.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” This works on this particular example, but xml.etree.ElementTree is not an HTML parser. Consider using BeautifulSoup: >>> from bs4 import BeautifulSoup >>> BeautifulSoup(url).a.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Or, lxml.html: >>> import lxml.html >>> lxml.html.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Personally, I prefer BeautifulSoup – … Read more