Return the id of a label's for attribute

def element_id_by_label(browser, label):
    """Return the id of a label's for attribute"""
    label = XPathSelector(browser,
                          unicode('//label[contains(., "%s")]' % label))
    if not label:
        return False
    return label.get_attribute('for')