Python Selenium FireFox 購買VPS

Python · 02-10 · 117 人浏览
Python Selenium FireFox 購買VPS

wap.ac、miaomiaomoe、wawo

import re
import time
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random
import string
import threading

def generate_random_string(length):
    characters = string.ascii_letters + string.digits  # 包含大小写字母和数字的所有字符
    return ''.join(random.choice(characters) for _ in range(length))

# 指定生成字符串的长度
length = 10

def wapac(email, password, goods_url, target_item, Code=None):
    # 创建 Firefox 浏览器实例
    driver = webdriver.Firefox()
    # 设置显式等待的最长等待时间为10秒
    wait = WebDriverWait(driver, 10)

    # 打开网页
    driver.get("https://wap.ac/login")

    # 获取页面标题
    title = driver.title
    print("獲取:", title)

    # email
    driver.find_element(By.ID, "inputEmail").send_keys(email)
    sleep(0.2)

    # password
    driver.find_element(By.ID, "inputPassword").send_keys(password)
    sleep(0.2)

    # login
    driver.find_element(By.ID, "login").click()

    # 等待页面刷新完毕,即出现 <退出账户>
    wait.until(EC.presence_of_element_located((By.ID, "Secondary_Sidebar-Client_Shortcuts-Logout")))


    # 以下開始循環:
    while True:
        driver.get(goods_url)

        # 使用显式等待确保页面加载完全
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".row.row-eq-height span")))

        goods_names = driver.find_elements(By.CSS_SELECTOR,
                                           "#order-standard_cart .products .product header span:first-child")
        goods_nums = driver.find_elements(By.CSS_SELECTOR, "#order-standard_cart .products .product header .qty")
        goods_config = driver.find_elements(By.CSS_SELECTOR, "#order-standard_cart .products .product div.product-desc")
        goods_links = driver.find_elements(By.CSS_SELECTOR, '.products footer .btn:not(:disabled):not(.disabled)')
        goods_money = driver.find_elements(By.CSS_SELECTOR, '#order-standard_cart .products .product div.product-pricing')

        # 循环遍历商品信息,寻找目标商品并购买
        for name_element, num_element, config_element, link_element, money_element in zip(goods_names, goods_nums, goods_config, goods_links, goods_money):
            # 获取商品信息的文本内容
            name = name_element.text

            num = num_element.text
            num = re.findall('(\d*) 可用', num)[0]

            config = config_element.text
            link = link_element.get_attribute("href")
            money = money_element.text

            # 判断当前商品是否是目标商品
            if name == target_item and int(num) != 0:
                # 点击购买按钮
                link_element.click()
                print(f"開始购买商品: {name}")

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteProductConfig")))

                # 生成随机字符串
                random_string = generate_random_string(length)

                # hostname
                driver.find_element(By.ID, 'inputHostname').send_keys(random_string + '.com')
                time.sleep(0.2)
                # root password
                driver.find_element(By.ID, 'inputRootpw').send_keys(random_string + random_string)
                time.sleep(0.2)
                # submit
                driver.find_element(By.ID, 'btnCompleteProductConfig').click()
                time.sleep(0.2)
                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "inputPromotionCode")))

                # Code
                if Code:
                    driver.find_element(By.ID, 'inputPromotionCode').send_keys(Code)
                    driver.find_element(By.CSS_SELECTOR, 'button.btn-block:nth-child(3)').click()
                    time.sleep(0.5)


                time.sleep(0.2)

                # checkout
                driver.find_element(By.ID, 'checkout').click()
                time.sleep(0.2)

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteOrder")))

                driver.find_element(By.XPATH, '/html/body/section/div/div[1]/div/div[1]/div/div[2]/form/div[8]/div/label[2]/div/ins').click()
                driver.find_element(By.XPATH, '/html/body/section/div/div[1]/div/div[1]/div/div[2]/form/div[14]/p/label/div/ins').click()
                driver.find_element(By.ID, 'btnCompleteOrder').click()
                print(f"已提交商品訂單: {name}")

                return True  # 购买完成后退出循环
            elif name == target_item and int(num) == 0:
                print(f"商品數量:: {num} 5s后嘗試刷新.....")

        time.sleep(5)
        driver.refresh()


def miaomiaomoe(email, password, goods_url, target_item, Code=None):
    # 创建 Firefox 浏览器实例
    driver = webdriver.Firefox()
    # 设置显式等待的最长等待时间为10秒
    wait = WebDriverWait(driver, 10)

    # 打开网页
    driver.get("https://miaomiao.moe/index.php?rp=/login")

    # 获取页面标题
    title = driver.title
    print("獲取:", title)

    # email
    driver.find_element(By.ID, "inputEmail").send_keys(email)
    sleep(0.2)

    # password
    driver.find_element(By.ID, "inputPassword").send_keys(password)
    sleep(0.2)

    # login
    driver.find_element(By.ID, "login").click()

    # 等待页面刷新完毕,即出现 <退出账户>
    wait.until(EC.presence_of_element_located((By.ID, "Secondary_Sidebar-Client_Shortcuts-Logout")))

    # 以下開始循環:
    while True:
        driver.get(goods_url)

        # 使用显式等待确保页面加载完全
        wait.until(EC.presence_of_element_located((By.ID, "order-standard_cart")))

        goods_names = driver.find_elements(By.CSS_SELECTOR,
                                           "#order-standard_cart .products .product header span:first-child")
        # goods_nums = driver.find_elements(By.CSS_SELECTOR, "#order-standard_cart .products .product header .qty")
        goods_config = driver.find_elements(By.CSS_SELECTOR, "#order-standard_cart .products .product div.product-desc")
        goods_links = driver.find_elements(By.CSS_SELECTOR, '.products footer .btn:not(:disabled):not(.disabled)')
        goods_money = driver.find_elements(By.CSS_SELECTOR, '#order-standard_cart .products .product div.product-pricing')

        # 循环遍历商品信息,寻找目标商品并购买
        for name_element, config_element, link_element, money_element in zip(goods_names, goods_config, goods_links, goods_money):
            # 获取商品信息的文本内容
            name = name_element.text

            config = config_element.text
            link = link_element.get_attribute("href")
            money = money_element.text

            # 判断当前商品是否是目标商品
            if name == target_item:
                # 点击购买按钮
                link_element.click()
                print(f"開始购买商品: {name}")

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteProductConfig")))

                # 生成随机字符串
                random_string = generate_random_string(length)

                # hostname
                driver.find_element(By.ID, 'inputHostname').send_keys(random_string + '.com')
                time.sleep(0.2)
                # root password
                driver.find_element(By.ID, 'inputRootpw').send_keys(random_string + random_string)
                time.sleep(0.2)

                driver.find_element(By.ID, 'inputNs1prefix').send_keys('ns1')
                driver.find_element(By.ID, 'inputNs2prefix').send_keys('ns2')


                # submit
                driver.find_element(By.ID, 'btnCompleteProductConfig').click()
                time.sleep(0.2)
                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "inputPromotionCode")))

                # Code
                if Code:
                    driver.find_element(By.ID, 'inputPromotionCode').send_keys(Code)
                    driver.find_element(By.CSS_SELECTOR, 'button.btn-block:nth-child(3)').click()
                    time.sleep(0.5)


                time.sleep(0.2)

                # checkout
                driver.find_element(By.ID, 'checkout').click()
                time.sleep(0.2)

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteOrder")))

                driver.find_element(By.ID, 'btnCompleteOrder').click()
                print(f"已提交商品訂單: {name}")

                return True  # 购买完成后退出循环

        time.sleep(5)
        driver.refresh()


def wawo(email, password, goods_url, target_item, Code=None):
    # 创建 Firefox 浏览器实例
    driver = webdriver.Firefox()
    # 设置显式等待的最长等待时间为10秒
    wait = WebDriverWait(driver, 10)

    # 打开网页
    driver.get("https://wawo.wiki/index.php?rp=/login")

    # 获取页面标题
    title = driver.title
    print("獲取:", title)

    # email
    driver.find_element(By.ID, "inputEmail").send_keys(email)
    sleep(0.2)

    # password
    driver.find_element(By.ID, "inputPassword").send_keys(password)
    sleep(0.2)

    # login
    driver.find_element(By.ID, "login").click()

    # 等待页面刷新完毕,即出现 <退出账户>
    wait.until(EC.presence_of_element_located((By.ID, "Secondary_Sidebar-Client_Shortcuts-Logout")))

    # 以下開始循環:
    while True:
        driver.get(goods_url)

        # 使用显式等待确保页面加载完全
        wait.until(EC.presence_of_element_located((By.ID, "order-standard_cart")))

        goods_names = driver.find_elements(By.CSS_SELECTOR,
                                           ".row .tt-product-name h5")
        goods_nums = driver.find_elements(By.CSS_SELECTOR, ".row div:nth-child(3) > span:nth-child(1)")
        goods_config = driver.find_elements(By.CSS_SELECTOR, ".row div:nth-child(4)")
        goods_links = driver.find_elements(By.CSS_SELECTOR, '.row .btn')
        goods_money = driver.find_elements(By.CSS_SELECTOR, '.row .small, small')

        # 循环遍历商品信息,寻找目标商品并购买
        for name_element, num_element, config_element, link_element, money_element in zip(goods_names, goods_nums, goods_config, goods_links, goods_money):
            # 获取商品信息的文本内容
            name = name_element.text

            num = num_element.text
            num = re.findall('(\d*) 可用', num)[0]


            config = config_element.text
            link = link_element.get_attribute("href")
            money = money_element.text



            # 判断当前商品是否是目标商品
            if name == target_item and int(num) != 0:
                # 点击购买按钮
                link_element.click()
                print(f"開始购买商品: {name}")

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteProductConfig")))

                # 生成随机字符串
                random_string = generate_random_string(length)

                # hostname
                driver.find_element(By.ID, 'inputHostname').send_keys(random_string + '.com')
                time.sleep(0.2)
                # root password
                driver.find_element(By.ID, 'inputRootpw').send_keys(random_string + random_string)
                time.sleep(0.2)
                # submit
                driver.find_element(By.ID, 'btnCompleteProductConfig').click()
                time.sleep(0.2)
                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "inputPromotionCode")))

                # Code
                if Code:
                    driver.find_element(By.ID, 'inputPromotionCode').send_keys(Code)
                    driver.find_element(By.CSS_SELECTOR, 'button.btn-block:nth-child(3)').click()
                    time.sleep(0.5)


                time.sleep(0.2)

                # checkout
                driver.find_element(By.ID, 'checkout').click()
                time.sleep(0.2)

                # 使用显式等待确保页面加载完全
                wait.until(EC.presence_of_element_located((By.ID, "btnCompleteOrder")))


                driver.find_element(By.ID, 'btnCompleteOrder').click()
                print(f"已提交商品訂單: {name}")

                return True  # 购买完成后退出循环
            elif name == target_item and int(num) == 0:
                print(f"商品數量:: {num} 5s后嘗試刷新.....")


        time.sleep(5)
        driver.refresh()


def wapac_thread():
    wapac('useremail', 'password', 'https://wap.ac/store/cn-gold-lxc-ipv6', 'CN 512 LXC')

def miaomiaomoe_thread():
    miaomiaomoe('useremail', 'password', 'https://miaomiao.moe/index.php?rp=/store/hgc-nat', 'HGC-Nano', '4A0ISNVLSD')

def wawo_thread():
    wawo('useremail', 'password', 'https://wawo.wiki/index.php?rp=/store/ams-ipv6kvm', 'amsbgp-ipv6-512')

# 创建线程,分别处理函数调用
thread1 = threading.Thread(target=wapac_thread)
thread2 = threading.Thread(target=miaomiaomoe_thread)
thread3 = threading.Thread(target=wawo_thread)

# 启动线程
thread1.start()
thread2.start()
thread3.start()

# 等待线程执行完成
thread1.join()
thread2.join()
thread3.join()
本站立足于美利堅合衆國,請讀者自覺遵守當地法律!如有違規,本站不承擔任何法律責任! This site is based in the United States of America, readers are requested to abide by local laws! If there are any violations, this site does not bear any legal responsibility! Theme Jasmine by Kent Liao