1. 抢购的配置等于或高于你的配置要求
2.声音提示
3.自动加入购物车,只需听到提示音付款,全自动
4.需要安装好requests和 selenium
需要修改的地方:
1.settings按照自己要求修改
2.chromedriver下载对应版本
driver = webdriver.Chrome(executable_path='E:\Work Area\chromedriver.exe', options=options)中executable_path换成你自己的
- import requests
- import json
- import re
- import time
- import sys
- import winsound
- from selenium import webdriver
- settings = {
- 'price': 15,
- 'virt': 'KVM',
- 'ram': 2000,
- 'cpu': 2,
- 'hdd': 20,
- 'bw': 1000,
- 'ips': 1,
- }
- url = 'https://billing.virmach.com/modules/addons/blackfriday/new_plan.json'
- options = webdriver.ChromeOptions()
- options.add_argument('--incognito')
- options.add_argument('--disable-gpu')
- driver = webdriver.Chrome(executable_path='E:\Work Area\chromedriver.exe', options=options)
- driver.get('https://www.baidu.com')
- def run():
- response = json.loads(requests.get(url).text)
- price = response['price']
- if 'yr' in price:
- price = float(re.findall('\$(.+?) <span>/yr</span>', price)[0])
- virt = response['virt']
- ram = int(response['ram'])
- cpu = int(response['cpu'])
- hdd = int(response['hdd'])
- bw = int(response['bw'])
- ips = int(response['ips'])
- pid = response['pid']
- location = response['location'] # BUFFALO
- if price <= settings['price'] and virt == settings['virt'] and ram >= settings['ram'] and cpu >= settings[
- 'cpu'] and hdd >= settings['hdd'] and bw >= settings['bw'] and ips >= settings['ips']:
- driver.get('https://billing.virmach.com/cart.php?a=add&pid=' + str(pid))
- winsound.Beep(500, 1000)
- print(price)
- print(cpu, 'H', ram, 'M', bw, 'G')
- print('hdd:', hdd, 'G')
- if ips > 1:
- print(ips)
- print(location)
- print('https://billing.virmach.com/cart.php?a=add&pid=' + str(pid))
- return True
- else:
- item = '无符合机器 ' + time.strftime("%H:%M:%S %Y-%m-%d", time.localtime())
- sys.stdout.write('\r' + str(item) + '\033[K')
- sys.stdout.flush()
- return False
- while 1:
- if run():
- break
- time.sleep(5)
复制代码
因为selenium启动比较慢 所以脚本开始的时候会事先打开一个网页
抢购到脚本会暂停,等待付款,需要重新运行开始下一轮
萌新,脚本有其他问题,欢迎反馈 代码丑勿喷 |