def get_link_text(link):
    """
    Return text of <a> element: either its string contents or the 'alt'
    of <img> tags inside.
    """
    txt = ' '.join(link.xpath('string()').extract())
    if not txt:
        txt = ' '.join(link.xpath('.//img/@alt').extract())
    return txt
