def get_parser(referring_url):
    """
    Utility function to find a parser for a referring URL if it is a SERP.

    :param referring_url: Suspected SERP URL.
    :type referring_url:  ``str`` or :class:`urlparse.ParseResult`

    :returns: :class:`SearchEngineParser` object if one exists for URL,
              ``None`` otherwise.
    """
    engines = _get_search_engines()
    url_parts = _unicode_urlparse(referring_url)
    if url_parts is None:
        return None

    query = _serp_query_string(url_parts)

    domain = url_parts.netloc
    path = url_parts.path
    lossy_domain = _get_lossy_domain(url_parts.netloc)
    engine_key = url_parts.netloc

    # Try to find a parser in the engines list.  We go from most specific to
    # least specific order:
    # 1. <domain><path>
    # 2. <lossy_domain><path>
    # 3. <lossy_domain>
    # 4. <domain>
    # The final case has some special exceptions for things like Google custom
    # search engines, yahoo and yahoo images
    if u'{}{}'.format(domain, path) in engines:
        engine_key = u'{}{}'.format(domain, path)
    elif u'{}{}'.format(lossy_domain, path) in engines:
        engine_key = u'{}{}'.format(lossy_domain, path)
    elif lossy_domain in engines:
        engine_key = lossy_domain
    elif domain not in engines:
        if query[:14] == 'cx=partner-pub':
            # Google custom search engine
            engine_key = 'google.com/cse'
        elif url_parts.path[:28] == '/pemonitorhosted/ws/results/':
            # private-label search powered by InfoSpace Metasearch
            engine_key = 'wsdsold.infospace.com'
        elif '.images.search.yahoo.com' in url_parts.netloc:
            # Yahoo! Images
            engine_key = 'images.search.yahoo.com'
        elif '.search.yahoo.com' in url_parts.netloc:
            # Yahoo!
            engine_key = 'search.yahoo.com'
        else:
            return None

    return engines.get(engine_key)
dataset/ETHPy150Open Parsely/serpextract/serpextract/serpextract.py/get_parser/original