def authenticity_token(dom, id=None):
    """
    Retrieves the CSRF auth token from the DOM for submission.
    If you need to differentiate between multiple CSRF tokens on one page,
    pass the optional ID of the parent form (with hash)
    """
    selector = 'input[name="authenticity_token"]:first'

    if id:
        selector = '{} {}'.format(id, selector)
    return dom.find(selector).attr('value')