import time
import random
import requests


def _get_page(url, s=None):
    """
    Utility function to play nice when scraping.
    This will also fetch a page according to a session or a simple get.
    """

    if not url:
        # What's a proper null requests object?
        return None
    # Play nice
    time.sleep(random.uniform(0.1, 0.3))
    if not s or isinstance(s, str):
        r = requests.get(url)
    else:
        # should check this is a valid session
        try:
            r = s.open(url)
        except:
            return None
    return r