Add clean_relativ_urls in genericArticle.py

and use it for ecrans.fr
This commit is contained in:
Florent 2012-11-07 18:13:03 +01:00
commit 3cb78d1729
2 changed files with 12 additions and 8 deletions

View file

@ -48,6 +48,16 @@ def drop_comments(base_element):
for comment in base_element.getiterator(Comment):
comment.drop_tree()
# Replace relative url in link and image with a complete url
# Arguments: the html element to clean, and the domain name (with http:// prefix)
def clean_relativ_urls(base_element, domain):
for a in base_element.findall('.//a'):
if a.attrib["href"][0:7] != "http://" and a.attrib["href"][0:7] != "https://":
a.attrib["href"] = domain + a.attrib["href"]
for img in base_element.findall('.//img'):
if img.attrib["src"][0:7] != "http://" and img.attrib["src"][0:7] != "https://":
img.attrib["src"] = domain + img.attrib["src"]
class NoAuthorElement(BrokenPageError):
pass