!/usr/bin/env python
-*- coding: utf-8 -*-
"""
通过splinter刷列车火车票
可以自动填充账号密码,同时,在登录时,也可以修改账号密码
然后手动识别验证码,并登陆,接下来的事情,交由脚本来做了,静静的等待抢票结果就好(刷票过程中,浏览器不可关闭)
"""
import re
from splinter.browser import Browser
from time import sleep
import time
import sys
import httplib2
from urllib import parse
import smtplib
import numpy as np
from email.mime.text import MIMEText
class BrushTicket(object):
"""买票类及实现方法"""
def __init__(self, user_name, password, passengers, from_time, from_station, to_station, number, seat_type):
"""定义实例属性,初始化"""
# 1206账号密码
self.user_name = user_name
self.password = password
# 乘客姓名
self.passengers = passengers
# 起始站和终点站
self.from_station = from_station
self.to_station = to_station
# 乘车日期
self.from_time = from_time
# 车次编号
self.number = number.capitalize()
# 座位类型所在td位置
if seat_type == '商务座特等座':
seat_type_index = 1
seat_type_value = 9
elif seat_type == '一等座':
seat_type_index = 2
seat_type_value = 'M'
elif seat_type == '二等座':
seat_type_index = 3
seat_type_value = 0
elif seat_type == '高级软卧':
seat_type_index = 4
seat_type_value = 6
elif seat_type == '软卧':
seat_type_index = 5
seat_type_value = 4