'Return the article\'s canonical URL
Gets the first available value of:
1. The rel=canonical tag
2. The og:url tag'

def get_canonical_link(self, article_url, doc):

    links = self.parser.getElementsByTag(doc, tag='link', attr='rel', value='canonical')
    canonical = (self.parser.getAttribute(links[0], 'href') if links else '')
    og_url = self.get_meta_content(doc, 'meta[property="og:url"]')
    meta_url = (canonical or og_url or '')
    if meta_url:
        meta_url = meta_url.strip()
        parsed_meta_url = urlparse(meta_url)
        if (not parsed_meta_url.hostname):
            parsed_article_url = urlparse(article_url)
            strip_hostname_in_meta_path = re.match('.*{}(?=/)/(.*)'.format(parsed_article_url.hostname), parsed_meta_url.path)
            try:
                true_path = strip_hostname_in_meta_path.group(1)
            except AttributeError:
                true_path = parsed_meta_url.path
            meta_url = urlunparse((parsed_article_url.scheme, parsed_article_url.hostname, true_path, '', '', ''))
    return meta_url
