python+splinterは自動的にチケット獲得機能を更新します。


チケットのシナリオを奪い取って、python+splinterは自動的に切符を奪い取って、成功して(自分のネットの環境に依存するのがあまりにすごいです。まだ機械の善し悪しがあります)を奪い取ることができて、しかし感じはそんなに完璧ではありません。
大神さんが指導して改善してください(あるいは他の良い考えがありますか?)。ありがとうございます。

# -*- coding: utf-8 -*-
"""
@author: liuyw
"""
from splinter.browser import Browser
from time import sleep
import traceback
import time, sys


class huoche(object):
 """docstring for huoche"""
 driver_name=''
 executable_path=''
 #   ,  
 username = u"[email protected]"
 passwd = u"xxxx"
 # cookies      ,          ,    
 starts = u"%u4E0A%u6D77%2CSHH"
 ends = u"%u592A%u539F%2CTYV"
 #     2018-01-19
 dtime = u"2018-01-19"
 #   ,     ,0         
 order = 0
 ###   
 users = [u"xxx",u"xxx"]
 ##  
 xb = u"   "
 pz=u"   "

 """  """
 ticket_url = "https://kyfw.12306.cn/otn/leftTicket/init"
 login_url = "https://kyfw.12306.cn/otn/login/init"
 initmy_url = "https://kyfw.12306.cn/otn/index/initMy12306"
 buy="https://kyfw.12306.cn/otn/confirmPassenger/initDc"
 login_url='https://kyfw.12306.cn/otn/login/init'
 def __init__(self):
  self.driver_name='chrome'
  self.executable_path='/usr/local/bin/chromedriver'


 def login(self):
  self.driver.visit(self.login_url)
  self.driver.fill("loginUserDTO.user_name", self.username)
  # sleep(1)
  self.driver.fill("userDTO.password", self.passwd)
  print u"     ,    ..."
  while True:
   if self.driver.url != self.initmy_url:
    sleep(1)
   else:
    break

 def start(self):
  self.driver=Browser(driver_name=self.driver_name,executable_path=self.executable_path)
  self.driver.driver.set_window_size(1400, 1000)
  self.login()
  # sleep(1)
  self.driver.visit(self.ticket_url)
  try:
   print u"      ..."
   # sleep(1)
   #       
   self.driver.cookies.add({"_jc_save_fromStation": self.starts})
   self.driver.cookies.add({"_jc_save_toStation": self.ends})
   self.driver.cookies.add({"_jc_save_fromDate": self.dtime})

   self.driver.reload()

   count=0
   if self.order!=0:
    while self.driver.url==self.ticket_url:
     self.driver.find_by_text(u"  ").click()
     count += 1
     print u"      ...   %s  " % count
     # sleep(1)
     try:
      self.driver.find_by_text(u"  ")[self.order - 1].click()
     except Exception as e:
      print e
      print u"      "
      continue
   else:
    while self.driver.url == self.ticket_url:
     self.driver.find_by_text(u"  ").click()
     count += 1
     print u"      ...   %s  " % count
     # sleep(0.8)
     try:
      for i in self.driver.find_by_text(u"  "):
       i.click()
       sleep(1)
     except Exception as e:
      print e
      print u"       %s" %count
      continue
   print u"    ..."
   # sleep(3)
   # self.driver.reload()
   sleep(1)
   print u'      ...'
   for user in self.users:
    self.driver.find_by_text(user).last.click()

   print u"    ..."
   sleep(1)
   # self.driver.find_by_text(self.pz).click()
   # self.driver.find_by_id('').select(self.pz)
   # # sleep(1)
   # self.driver.find_by_text(self.xb).click()
   # sleep(1)
   self.driver.find_by_id('submitOrder_id').click()
   # print u"    ..."
   # self.driver.find_by_id('1D').last.click()
   # self.driver.find_by_id('1F').last.click()

   sleep(1.5)
   print u"    ..."
   self.driver.find_by_id('qr_submit_id').click()


  except Exception as e:
   print e


if __name__ == '__main__':
 huoche=huoche()
 huoche.start()
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。