# coding: utf-8
import time

from lxml import etree


def switch_domain(country):
    domain = "https://vendorcentral.amazon.com/"

    if country == "JP":
        domain = "https://vendorcentral.amazon.co.jp/"
    if country == "UK":
        domain = "https://vendorcentral.amazon.co.uk/"
    if country == "FR":
        domain = "https://vendorcentral.amazon.fr/"
    if country == "CA":
        domain = "https://vendorcentral.amazon.ca/"
    if country == "mx":
        domain = "https://vendorcentral.amazon.com.mx/"

    return domain


def domain_page(page,country):
    url = switch_domain(country)
    page.get(url)
    while True:
        time.sleep(1)
        title = page.title
        valid_titles = [
            "Amazon Sign-In",
            "Amazon Sign In",
            "Connexion Amazon",
            "Amazonサインイン",
            "Amazon Iniciar sesión"
        ]
        if title in valid_titles:
            print("请登录账号")
            continue

        tree = etree.HTML(page.html)
        element = tree.xpath('//*[@id="cvf-submit-otp-button-announce"]')
        if element:
            print('请输入验证码')
        else:
            break