其实之前的绿云的脚本稍微改动一下就可以抢斯巴达的机器了,但是很多人不会改,为了备战黑五,提前把脚本给大家撸出来了。
由于斯巴达在提交的最后一步是reCAPTCHA,这个如果想自动过要花钱买,还挺贵的,我在这里自动填充完成后留了10分钟,自己过下验证码点提交订单就可以了。
逻辑上还有优化的地方,有空再改吧。
使用方法和绿云的一样,保存后使用python 运行
import undetected_chromedriver as uc import requests import time import random from selenium.webdriver import Keys from selenium.webdriver.common.by import By def buy_service(): # 这里是生成随机Hostname,你可以改为你的Hostname hostname = str(random.randint(10000, 99999)) + '.baidu.com' # 这里是生成随机密码,你可以改为你的密码 rootpw = ''.join(random.sample('zyxwvutsrqponmlkjihgfedcba!', 4)) + str(random.randint(100000, 999999)) print('Your root password:' + rootpw) # 购买商品的链接 特价机的gid=60,演示中设置gid=25 url = 'https://billing.spartanhost.net/cart.php?a=add&pid=27' # 是否显示界面,linux下面这一行要放开。 # option.add_argument("headless") uc_options = uc.ChromeOptions() # tried this first uc_options.headless = False # Then tried this option driver = uc.Chrome(options=uc_options) # 打开网页 driver.get(url) driver.find_element(by=By.XPATH, value='//input[@id="customfield35"]').send_keys("hostloc") driver.find_element(by=By.XPATH, value='//*[@id="btnCompleteProductConfig"]').click() time.sleep(2) try_time = 1 # 有优惠码的时候使用 # for try_time in range(1, 7): # try: # time.sleep(0.24) # driver.find_element(by=By.XPATH, value='//input[@name="promocode"]').send_keys('') # except Exception: # try_time = try_time + 1 # pass # if try_time == 6: # print("得你手动了骚年!") # break # else: # break # driver.find_element(by=By.XPATH, value='/html/body/section[2]/div/div/div/div[1]/div/div/div[3]/div[2]/div[1]/div/div/div[1]/form/button').click() # time.sleep(0.7) driver.find_element(by=By.XPATH, value='//*[@id = "checkout"]').click() time.sleep(2) driver.find_element(by=By.XPATH, value='//button[@id="btnAlreadyRegistered"]').click() # 购买者邮箱 time.sleep(2) driver.find_element(by=By.XPATH, value='//input[@name="loginemail"]').send_keys("username@qq.com") # 账号密码 driver.find_element(by=By.XPATH, value='//input[@name="loginpassword"]').send_keys("mjj123123") # 最后这一行是付款界面的"点击结算".如果你想要测试脚本是否正常运行,可以先把这一句去掉,以免购买了给你发账单(虽然可以不付款)+ driver.find_element(by=By.XPATH, value='//input[@id="accepttos"]').send_keys(Keys.SPACE) time.sleep(600) driver.find_element(by=By.XPATH, value='//button[@id="btnCompleteOrder"]').click() print("抢购成功!") if __name__ == '__main__': order = False header = { 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'} # 逻辑判断 while not order: # 检测商品上货的链接 特价机的gid=60,演示中设置gid=25 response = requests.get(url='https://billing.spartanhost.net/cart.php?a=add&pid=27', headers=header) if 'Out of Stock' in str(response.content): print('Mei Huo') print('时间:' + time.strftime('%H:%M:%S')) print("*" * 30) time.sleep(3) else: order = True if order: buy_service()
暂无评论
请先登录后发表评论!
暂无评论