def next_page(dom):
    """Gets link for next page for results from apihub/scihub

    :param dom: object coming back from a Copernicus' scihub search request
    :type dom: xml.dom object
    :return: Link ot the next page or None if we reached the end.
    :rtype: str
    """

    links = dom.getElementsByTagName('link')
    next_page_, this_page, last = None, None, None

    for link in links:
        if link.getAttribute('rel') == 'next':
            next_page_ = link.getAttribute('href')
        elif link.getAttribute('rel') == 'self':
            this_page = link.getAttribute('href')
        elif link.getAttribute('rel') == 'last':
            last = link.getAttribute('href')

    if last == this_page:  # we are not at the end
        next_page_ = None

    return next_page_