淘宝秒杀、京东秒杀、WHU图书馆抢座系统

淘宝双十一秒杀系统(可提前加入购物车)

# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
    driver.get("https://www.taobao.com/")
    driver.find_element_by_link_text("亲,请登录").click()
    driver.find_element_by_link_text("密码登录").click()
    driver.find_element_by_name("TPL_username").send_keys(uname)
    driver.find_element_by_name("TPL_password").send_keys(pwd)
    driver.find_element_by_id("J_SubmitStatic").click()
    time.sleep(3)
    driver.get("https://cart.taobao.com/")
    time.sleep(3)
    driver.find_element_by_xpath('//input[@name="select-all"]').click()  # click
    driver.find_element_by_link_text("结 算").click()
    now = datetime.datetime.now()
    print now.strftime('%Y-%m-%d %H:%M:%S')
    print 'login success'
# buytime = '2016-12-27 22:31:00'
def buy_on_time(buytime):
    while True:
        now = datetime.datetime.now()
        if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
            driver.find_element_by_class_name('go-btn').click()
            time.sleep(3)
            print now.strftime('%Y-%m-%d %H:%M:%S')
            print 'purchase success'
        time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 19:37:00')

淘宝聚划算系统(不可提前得到秒杀地址)

# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
    driver.get("https://www.taobao.com/")
    driver.find_element_by_link_text("亲,请登录").click()
    driver.find_element_by_link_text("密码登录").click()    driver.find_element_by_name("TPL_username").send_keys(uname)
    driver.find_element_by_name("TPL_password").send_keys(pwd)
    driver.find_element_by_id("J_SubmitStatic").click()
    time.sleep(3)
    now = datetime.datetime.now()
    print now.strftime('%Y-%m-%d %H:%M:%S')
    print 'login success'
# buytime = '2016-12-27 22:31:00'
def buy_on_time(buytime):
    while True:
        now = datetime.datetime.now()
        if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
            #时间到,开始get界面
            driver.get("https://detail.ju.taobao.com/home.htm?spm=608.2291429.102212b.1.24817b560Bv0M9&id=10000052045940&item_id=27089572187")
            # 聚划算界面
            time.sleep(2)
            driver.find_element_by_class_name("piclink").click()
            driver.switch_to.window(driver.window_handles[1])
            driver.find_element_by_class_name("J_LinkBuy").click()
            time.sleep(2)
            driver.find_element_by_class_name('go-btn').click()
            print now.strftime('%Y-%m-%d %H:%M:%S')
            print 'purchase success'
        time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 19:37:00')

京东秒杀系统

# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
    driver.get("http://www.jd.com")
    driver.find_element_by_link_text("你好,请登录").click()
    time.sleep(3)
    driver.find_element_by_link_text("账户登录").click()
    driver.find_element_by_name("loginname").send_keys(uname)
    driver.find_element_by_name("nloginpwd").send_keys(pwd)
    driver.find_element_by_id("loginsubmit").click()
    time.sleep(3)
    driver.get("https://cart.jd.com/cart.action")
    time.sleep(3)
    #购物车中只有一件商品时才会自动勾选
    driver.find_element_by_link_text("去结算").click()
    now = datetime.datetime.now()
    print now.strftime('%Y-%m-%d %H:%M:%S')
    print 'login success'

def buy_on_time(buytime):
    while True:
        now = datetime.datetime.now()
        if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
            driver.find_element_by_id('order-submit').click()
            time.sleep(3)
            print now.strftime('%Y-%m-%d %H:%M:%S')
            print 'purchase success'
        time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 16:01:00')

街道口职业技术学院图书馆抢座系统

需要安装OCR环境http://www.jianshu.com/p/19c82f64cd60

# -*- coding: utf-8 -*-
from selenium import webdriver
import datetime
import os
import pytesser
import sys,time
from PIL import Image

reload(sys)
PostUrl = "http://seat.lib.whu.edu.cn/login?targetUri=%2F#"

driver=webdriver.Firefox()
driver.get(PostUrl)

def image_file_to_string(file):
    cwd = os.getcwd()
    try:
        os.chdir("C:\\Python27\\Lib\\site-packages\pytesser")
        return pytesser.image_file_to_string(file)
    finally:
        os.chdir(cwd)

def tryy():
    # 对验证码进行区域截图
    driver.get_screenshot_as_file("C:\\Users\\yingtaomj\\PycharmProjects\\test\\image.jpg")  # 比较好理解
    im = Image.open('C:\\Users\\yingtaomj\\PycharmProjects\\test\\image.jpg')
    box = (950, 324, 1058, 357)  # 设置要裁剪的区域
    region = im.crop(box)  # 此时,region是一个新的图像对象。
    region = region.convert('RGB')
    region.save("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg")
    im = Image.open("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg")
    code = image_file_to_string("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg")  # code即为识别出的图片数字str类型
    print code
    # 打印code观察是否识别正确
    elem_user = driver.find_element_by_name('username')
    elem_psw = driver.find_element_by_name('password')
    elem_code = driver.find_element_by_name('captcha')
    elem_user.send_keys('学号')
    elem_psw.send_keys('密码')
    elem_code.send_keys(code)

#代码不够完善,有时会读取成标点符号报错,只能重新运行一下
#验证码不一定识别正确,因为要循环识别直到成功
while True:
    tryy()
    try:
        driver.find_element_by_name("password")
    except:
        break

driver.find_element_by_link_text("常用座位").click()

buytime='2017-07-12 22:30:00'
startime='09:00'
endtime='21:00'
while True:
    now = datetime.datetime.now()
    #十点半啦!开始抢座啦!
    if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
        driver.find_element_by_id("display_onDate").click()
        driver.find_element_by_xpath("//a[@value='2017-07-12']").click()
        driver.find_element_by_id("seat_6145").click()
        #图方便只能在常用座位选,每个座位都有自己的id "seat_xxxx
        try:
            driver.find_element_by_link_text(startime).click()
            driver.find_element_by_link_text(endtime).click()
            driver.find_element_by_link_text("预 约").click()
        except:
            driver.find_element_by_link_text("取 消").click()
            #如果第一个没抢成功就看第二个
            driver.find_element_by_id("seat_6172").click()
            #不sleep一下程序有可能报错
            time.sleep(0.5)
            driver.find_element_by_link_text(startime).click()
            time.sleep(0.5) 
            driver.find_element_by_xpath("/html/body/div/div/div[3]/dl/ul/li[2]").click()#li的序号是多少取决于想订到几点
            time.sleep(0.5)
            driver.find_element_by_link_text("预 约").click()

你可能感兴趣的:(淘宝秒杀、京东秒杀、WHU图书馆抢座系统)