国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python+splinter自動(dòng)刷新?lián)屍惫δ?/h1>
2020-01-04 14:28:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

搶票腳本,python +splinter自動(dòng)刷新?lián)屍保梢猿晒尩剑ㄒ蕾囎约旱木W(wǎng)絡(luò)環(huán)境太厲害,還有機(jī)器的好壞),但是感覺(jué)不是很完美。

有大神請(qǐng)指導(dǎo)完善一下(或者有沒(méi)有別的好點(diǎn)的思路),不勝感謝。

# -*- coding: utf-8 -*-"""@author: liuyw"""from splinter.browser import Browserfrom time import sleepimport tracebackimport time, sysclass huoche(object): """docstring for huoche""" driver_name='' executable_path='' #用戶名,密碼 username = u"xxx@qq.com" passwd = u"xxxx" # cookies值得自己去找, 下面兩個(gè)分別是上海, 太原南 starts = u"%u4E0A%u6D77%2CSHH" ends = u"%u592A%u539F%2CTYV" # 時(shí)間格式2018-01-19 dtime = u"2018-01-19" # 車次,選擇第幾趟,0則從上之下依次點(diǎn)擊 order = 0 ###乘客名 users = [u"xxx",u"xxx"] ##席位 xb = u"二等座" pz=u"成人票" """網(wǎng)址""" 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"等待驗(yàn)證碼,自行輸入..."  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"購(gòu)票頁(yè)面開(kāi)始..."   # 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"循環(huán)點(diǎn)擊查詢... 第 %s 次" % count     # sleep(1)     try:      self.driver.find_by_text(u"預(yù)訂")[self.order - 1].click()     except Exception as e:      print e      print u"還沒(méi)開(kāi)始預(yù)訂"      continue   else:    while self.driver.url == self.ticket_url:     self.driver.find_by_text(u"查詢").click()     count += 1     print u"循環(huán)點(diǎn)擊查詢... 第 %s 次" % count     # sleep(0.8)     try:      for i in self.driver.find_by_text(u"預(yù)訂"):       i.click()       sleep(1)     except Exception as e:      print e      print u"還沒(méi)開(kāi)始預(yù)訂 %s" %count      continue   print u"開(kāi)始預(yù)訂..."   # sleep(3)   # self.driver.reload()   sleep(1)   print u'開(kāi)始選擇用戶...'   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"開(kāi)始選座..."   # self.driver.find_by_id('1D').last.click()   # self.driver.find_by_id('1F').last.click()   sleep(1.5)   print u"確認(rèn)選座..."   self.driver.find_by_id('qr_submit_id').click()  except Exception as e:   print eif __name__ == '__main__': huoche=huoche() huoche.start()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到python教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

主站蜘蛛池模板: 台北市| 合川市| 聂拉木县| 酉阳| 庆阳市| 万宁市| 上虞市| 留坝县| 邯郸市| 新河县| 西藏| 马尔康县| 普定县| 鄂伦春自治旗| 永顺县| 吉木萨尔县| 中宁县| 中江县| 桃园市| 周宁县| 谷城县| 西丰县| 北碚区| 九寨沟县| 泸西县| 吉木乃县| 浮山县| 大洼县| 合水县| 京山县| 富蕴县| 兴义市| 长岭县| 庆城县| 漠河县| 永州市| 米林县| 明星| 望都县| 肥西县| 蒙城县|