前言:我想在源文章里加入下面一段來著,但是實在加不上,報什麼405,造成安全威脅,不好意思哈各位,這麼點內容還另起一章實在不好意思哈。
千萬別一直掛著會封ip的,別問我怎麼知道的,我不想說T_T
程式碼如下:
雖然還是存在很多的問題,但是真的不願意改了,票買到了就沒什麼動力,大家懂得,上面的程式碼的確存在問題不好意思:
# -*- coding: utf-8 -*- """ Created on Fri Dec 04 00:35:24 2015 @author: Ye """ from splinter.browser import Browser from time import sleep #使用者名稱,密碼 username = "使用者名稱" passwd = "密碼" #cookies值得自己去找,下面兩個分別是上海,長沙,怎麼找blog中說明了 starts = "%u4E0A%u6D77%2CSHH" ends = "%u957F%u6C99%2CCSQ" #時間格式2016-01-31 dtime = "2016-02-02" #車次,選擇第幾趟,0則從上之下依次點選 order = 0 ###乘客名 pa = u"乘客名(常用聯絡人)" ###車次型別 ttype="GC-高鐵/城際" #網址 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" config_url = "https://kyfw.12306.cn/otn/confirmPassenger/initDc" def login(): b.find_by_text(u"登入").click() sleep(3) b.fill("loginUserDTO.user_name",username) sleep(1) b.fill("userDTO.password",passwd) sleep(1) b.execute_script(`alert("自行輸入驗證碼吧~")`) print u"等待驗證碼,自行輸入..." sleep(10) def huoche(): global b b = Browser(driver_name="chrome") b.visit(ticket_url) b.execute_script(`alert("開始刷票嘍~~~~")`) sleep(2) b.get_alert().dismiss() while b.is_text_present(u"登入"): sleep(1) login() if b.url == initmy_url: break try: #跳回購票頁面 b.visit(ticket_url) #載入查詢資訊 b.cookies.add({"_jc_save_fromStation":starts}) b.cookies.add({"_jc_save_toStation":ends}) b.cookies.add({"_jc_save_fromDate":dtime}) b.reload() i = 1 #迴圈點選預訂 if order != 0: while b.url == ticket_url: b.find_by_text(u"查詢").click() # b.find_by_text(ttype).click() if b.find_by_text(u"預訂"): sleep(0.3) b.find_by_text(u"預訂")[order - 1].click() print b.url if b.is_text_present(u"證件號碼",wait_time=0.2): # print [ i.text for i in b.find_by_text(pa) ] b.find_by_text(pa)[1].click() else: b.execute_script(`alert("似乎沒有可預訂選項")`) b.get_alert().dismiss() pass else: while b.url == ticket_url: b.find_by_text(u"查詢").click() if b.find_by_text(u"預訂"): sleep(0.3) for i in b.find_by_text(u"預訂"): i.click() sleep(0.1) if b.is_text_present(u"證件號碼"): b.find_by_text(pa)[1].click() else: b.execute_script(`alert("似乎沒有可預訂選項")`) b.get_alert().dismiss() pass b.execute_script(`alert("能做的都做了")`) b.get_alert().dismiss() print u"能做的都做了.....不再對瀏覽器進行任何操作" except Exception: print u"出錯了...." if __name__ == "__main__": huoche()
放上來怎麼沒有縮排了T_T
好吧,還是百度雲吧