當前位置:首頁 » 編程語言 » python搶票代碼

python搶票代碼

發布時間: 2023-01-16 14:48:00

1. 大家用python都做過什麼

一起來看看Python語言的用途盤點~
1、搶票
大家出去旅遊或者留學生放假需要買往返機票的時候,為了買到最低或相對低價的票,常常需要下好幾個手機App,或者連續幾天不停登錄不同的網站來回比價!費時費力不說,有時候買完票發現還有更便宜的,這就很難受了。不過用Python(BeautifulSoup,Tinyurl,Googlevoice包)寫個抓機票網站查詢結果網頁的程序,放到Amazon EC2的伺服器上,每十五分鍾抓一下網頁的票價,低於某個價格就調用Google Voice的發簡訊功能把URL發條簡訊給自己搶票!同理,Python還可以用來搶火車票。相信國內異地工作or學習的朋友們都經歷過,春運的票真的好難搶。GitHub上用Python搶票的項目在春運前就又重回到另了Top榜單。
2、畫畫
這里說的畫畫,不是真的然計算機可以直接進行繪畫創作,而是用Python對圖片進行藝術加工。說白了,就是通過Python語言的深度學習演算法包去訓練計算機模仿世界名畫的風格。比如梵高的名作《向日葵》作為模板,在順便選擇一個待轉化的圖片,就能利用Python把普通的圖片轉化成大師的作品風格。聽上去好像沒有什麼實際的用處,實際上可以為我們的生活增添不少藝術性。假以時日,隨著Python在藝術繪畫領域的發展,相信會為我們帶來更大的驚喜!
3、數據可視化
Python已經成為數據分析的首選語言。對於像pandas,NumPy和matplotlib這樣以數據為中心的庫,任何熟悉Python語言的語法和規則的人都可以將其部署為處理,操作和可視化數據的強大工具。
4、自動化腳本
Python可以自動化的批量處理大量的數據,因此自動化腳本用 Python 來寫是很爽的,那些頻繁的、重復的、無腦的操作,你都可以自己寫一個 Python 腳本讓電腦幫你操作,可以節省你大量的時間。別人一個文件一個文件的操作,一條命令一條命令的執行。
5、web應用開發
在國內,豆瓣一開始就使用Python作為web開發基礎語言,知乎的整個架構也是基於Python語言,這使得web開發這塊在國內發展的很不錯。 youtube 世界最大的視頻網站也是Python開發的哦~還有非常出名的instagram 也是用Python開發的。因此,目前國內的Python開發崗位也一直在增加。
因此,掌握Python語言能做的事情實在是太多了!在未來,隨著人工智慧和大數據的發展,相信Python的應用會更加廣泛。

2. 如何用python寫一個簡單的12306搶票軟體

#coding=utf-8
from selenium import webdriver
from time import sleep
import traceback

TICKET_URI = 'https://kyfw.12306.cn/otn/leftTicket/init'
LOGIN_URI = 'https://kyfw.12306.cn/otn/login/init'
MY_URI = 'https://kyfw.12306.cn/otn/index/initMy12306'
LOGIN = u'登錄'

from splinter.browser import Browser
from time import sleep
import traceback

TICKET_URI = 'https://kyfw.12306.cn/otn/leftTicket/init'
LOGIN_URI = 'https://kyfw.12306.cn/otn/login/init'
MY_URI = 'https://kyfw.12306.cn/otn/index/initMy12306'
LOGIN = 'login_user'

def login():
brw.find_element_by_id(LOGIN).click()
sleep(3)

uname = '[email protected]'
pwd = 'xxxyyyzzz'

brw.find_element_by_id('username').send_keys(uname)
sleep(1)
brw.find_element_by_id('password').send_keys(pwd)
sleep(1)

while True:
if brw.current_url != MY_URI:
sleep(1)
else:
break

def addCookie(cklist):
li = list()
for d in cklist:
if d['name'] == '_jc_save_toStation' or d['name'] == '_jc_save_toDate' or d['name'] == '_jc_save_fromStation':
li.append(d)
return li

def book():
global brw

brw = webdriver.Chrome()
brw.set_window_size(1366, 768)
brw.get(TICKET_URI)

sleep(3)

while brw.find_element_by_id(LOGIN):
login()
if brw.current_url == MY_URI:
break;

try:
brw.get(TICKET_URI)
sleep(2)
# set src
brw.find_element_by_id('fromStationText').clear()
brw.find_element_by_id('fromStationText').click()
brw.find_element_by_id('fromStationText').send_keys(u'合肥南')
sleep(3)

# set dst
brw.find_element_by_id('toStationText').clear()
brw.find_element_by_id('toStationText').click()
brw.find_element_by_id('toStationText').send_keys(u'武漢')
sleep(3)

# set left date
print('please click train date')
sleep(5)

cke = brw.get_cookies()
li = addCookie(cke)
for x in li:
brw.add_cookie(x)

brw.refresh()

count = 0
success = False
if not success:
while brw.current_url == TICKET_URI:
brw.find_element_by_id('query_ticket').click()
sleep(2)
print(u'第%d次刷新' % count)
count += 1
brw.find_element_by_partial_link_text('D3057')

except Exception as e:
print(traceback.print_exc())

if __name__ == "__main__":
book()

3. 如何用python寫一個簡單的12306搶票軟體

我有用Python攻克12306最後一道防線,實現自動搶票的教程,

4. Python用selenium實現模擬登錄,各種搶票腳本的第一步

selenium >>> pip install selenium==3.4.1

第一次登陸的時候,會幫助我記錄我們的登陸信息

登陸成功之後 cookie會發生變化

假如我現在已經登陸過了,那麼直接拿本地的登陸信息,直接登陸就可以了

調用登陸,並且刷新頁面,改變登陸成功的標識

5. 我從github上下載了python12306的搶票程序,但運行時一堆錯誤,求各位大神幫幫忙哈

貼一下具體鏈接呢
還有github上的代碼,一般star至少要幾十個的,才有一定質量保證

6. Python:基於Python爬蟲技術的搶票程序及其實現

臨近放假,相信我們每天都在群聊里或者朋友圈看到一些幫忙搶火車票的信息。看到朋友們搶回家的車票這么辛( bei )苦( can ),結合圈裡一些前輩的指點,抱著學習的心態用 Python 做了一個簡單的自動化搶票程序,搶到票之後通過綁定的郵箱(比如 QQ )發通知。下面分享主要內容:

然後,開始使勁地碼:

1. 定義自動購票的類(初始化屬性)

2. 實現登錄功能

3. 實現購票功能

4. 郵箱通知付款

還有,網路不好或者 12306 的伺服器不穩定的時候,就會卡住,針對這種情況,系統會重復查詢:

最後,祝大家都能順利搶到票.

本文以轉載於博客園小帝君的博客

7. 如何用python寫一個簡單的12306搶票軟體

看看這個可以嗎功能:1:全自動爬所有車站列表2:爬所有車站之間的所有車次,過濾重復,保存文件爬過程中保存文件遇到http異常,停止繼續腳本代碼[python]viewplain#coding:utf-8__author__='watsy'#城市對象classcityObject(object):def__init__(self,abbr_pinyin="",full_pinyin="",chinaname="",shortCode=""):self.abbr_pinyin=abbr_pinyinself.full_piyin=full_pinyinself.chinaname=chinanameself.shortCode=shortCode#火車classtrainObject(object):def__init__(self,tid="",code="",start_city="",start_time="",end_city="",end_time="",full_time=""):self.tid=tidself.code=codeself.start_city=start_cityself.start_time=start_timeself.end_city=end_cityself.end_time=end_timeself.full_time=full_timedefget_writestr(self):#return("%s,%s,%s,%s,%s,%s,%s")%(self.tid,self.code,self.start_city.encode('utf-8'),self.start_time,self.end_city.encode('utf-8'),self.end_time,self.full_time)str_return=self.tid+",";str_return+=self.code+",";str_return+=self.start_city+",";str_return+=self.start_time+",";str_return+=self.end_city+",";str_return+=self.end_time+",";str_return+=self.full_time;returnstr_return#火車列表classtrainModel(list):defisExist(self,train):forsub_traininself:ifsub_train.code==train.code:returnTruereturnFalsedefsave(self):train=self[-1]withopen(("%s.txt")%(train.code),"w")aswf:printtrain.get_writestr()wf.write(train.get_writestr().encode('utf-8'))#解析城市defparserCitys(data):parser_citys=[]fororiginal_cityindata:iforiginal_cityandlen(original_city)>1:split_city=original_city.split('|')parser_city=cityObject(split_city[0],split_city[3],split_city[1],split_city[2])parser_citys.append(parser_city)printlen(parser_citys)returnparser_citys#生成url地址defgetBookingTrainListUrl(start_code,end_code,day):strUrl=("/otsquery/query/queryRemanentTicketAction.do?method=queryLeftTicket&")strUrl+=("orderRequest.train_date=%s&")%(day)strUrl+=("orderRequest.from_station_telecode=%s&")%(start_code)strUrl+=("orderRequest.to_station_telecode=%s&")%(end_code)strUrl+=("orderRequest.train_no=&trainPassType=QB&trainClass=QB%23D%23Z%23T%23K%23QT%23&includeStudent=00&seatTypeAndNum=&orderRequest.start_time_str=00%3A00--24%3A00")returnstrUrltrains=trainModel()#解析預定車次列表defparser_booking_str(str_booking):json_book=json.loads(str_booking)datas=json_book['datas']ifdatasandlen(datas)>1:#printdatas.replace("","")trainlist=datas.replace("","").split("\\n")fortrain_strintrainlist:train_str_list=train_str.split(',')iflen(train_str_list)==17:str_id_and_code=train_str_list[1]str_start_city_and_time=train_str_list[2]str_end_city_and_time=train_str_list[3]str_full_time=train_str_list[4]#printstr_id_and_codestr_id=str_id_and_code[13:25]str_code=str_id_and_code[131:-7]#printstr_start_city_and_timeiflen(str_start_city_and_time)>50:str_start_city=str_start_city_and_time[43:-9]else:str_start_city=str_start_city_and_time[0:-9]str_start_time=str_start_city_and_time[-5:]#printstr_end_city_and_timeiflen(str_end_city_and_time)>50:str_end_city=str_end_city_and_time[42:-9]else:str_end_city=str_end_city_and_time[0:-9]str_end_time=str_end_city_and_time[-5:]tobj=trainObject(str_id,str_code,str_start_city,str_start_time,str_end_city,str_end_time,str_full_time)iftrains.isExist(tobj)==False:trains.append(tobj)trains.save()#打開城市列表頁面u=urllib2.urlopen("mon/station_name.js?version=1.40")buffer=u.read()u.close()#獲取列表buffer=buffer[20:-3]unformatter_citys=buffer.split('@')#得到城市parser_citys=parserCitys(unformatter_citys)city_length=len(parser_citys)today=datetime.date.today()torrow=datetime.timedelta(days=1)today=today+torrowday_str=("%s-%02d-%02d")%(today.year,int(today.month),int(today.day))print(day_str)strPath=os.getcwd()os.chdir("%s/train/"%strPath)foriinrange(1,city_length):forjinrange(0,len(parser_citys)-i):try:print("[%d%d]"%(i,j))sleep(0.09)strurl=getBookingTrainListUrl(parser_citys[i].shortCode,parser_citys[j].shortCode,day_str)url_add_header=urllib2.Request(strurl)url_add_header.add_header('X-Requested-With',"XMLHttpRequest")url_add_header.add_header('Referer',"/otsquery/query/queryRemanentTicketAction.do?method=init")url_add_header.add_header('Content-Type','application/x-www-form-urlencoded')url_add_header.add_header('Connection','keep-alive')resp=urllib2.urlopen(url_add_header)urlread=resp.read()resp.close()parser_booking_str(urlread)excepturllib2.HTTPErroraserr:print("error:[%s]url=[%s]")%(err,strurl)exit(1)os.chdir(strPath)printlen(trains)

8. 如何寫搶票軟體python實現

你自己的問題都不詳細,別人怎麼會給你詳細的答案。 搶票軟體一般也就是模擬瀏覽器發請求,當然純粹模擬也會有很多問題,比如驗證碼,請求數等等,具體看你要實現什麼效果。

9. 用python搶票犯法嗎

犯法
用python搶購火車票是犯法的,乘客切記不要去以身試法。如果想要增加成功搶購到車票的幾率,可以採用以下這些方式的:
1、在車票售賣的當天進行手動搶票,在車票開始售賣之前的3到5分鍾時間進入到12306裡面去等待。之後在車票售賣前30秒開始刷新售賣車票的頁面,因為售賣車票的時間是不固定的,有可能會提前放票,一旦搶到車票後,就需要及時驗證。
2、搶票期間必須要有一個不錯的網路環境,並且手機彈出頁面的速度跟別人對比快很多。還有刷新的手速要快,盡量是搶到車票後就能立刻驗證,並且完成支付的。
3、首先乘客可以先在12306軟體上預約搶票,如果沒有餘票就去提交候補車票訂單。候補的速度要快,排名越前成功的幾率就會更高,另外還能在第三方購票軟體上購買加速包一起搶購
如果不想要購買加速包,就能使用多個購票軟體一起搶票,比如攜程、智行、途牛、同程等。如果其中一個訂單成功搶到票,要及時取消其他搶票訂單,不然退票是需要手續費的。
正常情況下,列車發車之前的2天時間會有少數乘客辦理退票手續。此時乘客可以經常去刷新下售賣車票的頁面,也還是有可能會搶到車票的。即便乘客已經提交了候補車票的訂單,還是要經常手動刷新購票頁面,從而提升購票成功的幾率。
法律依據
《刑法》
第二百二十五條
規定違反國家規定,有該條所列非法經營行為之
一,擾亂市場秩序的犯罪。這些非法經營行為包括:(一)未經許可經營法律、行政法規規定的專營、專賣物品或者其他限制買賣的物品的;(二)買賣進出口許可證、進出口原產地證明以及其他法律、行政法規規定的經營許可證或者批准文件的;(三)未經國家有關主管部門批准非法經營證券、期貨、保險業務的,或者非法從事資金支付結算業務的;(四)其他嚴重擾亂市場秩序的非法經營行為。
第二百八十五條
規定提供侵入、非法控制計算機信息系統程序、工具罪是指提供專門用於侵入、非法控制計算機信息系統的程序、工具,或者明知他人實施侵入、非法控制計算機信息系統的違法犯罪行為而為其提供程序、工具,情節嚴重的行為。該罪在客觀方面表現為提供專門侵入、非法控制計算機信息系統的程序、工具,或者明知他人實施侵入、非法控制計算機信息系統的違法犯罪行為而為其提供程序、工具,情節嚴重的行為。

10. 如何用python寫一個簡單的12306搶票軟體

所謂搶票實際上是在開始放票的一瞬間第一個發出請求並點擊預訂。作為程序員的我們,完全可以讓程序來做這件事。我花了幾個小時寫了一個demo。用到的工具集有:Python3.6, Selenium, chromdriver. 程序本身就是流程性的東西,沒有什麼可介紹的。代碼如下

#
coding=utf-8

from
selenium import
webdriver

from
time import
sleep

import
traceback

TICKET_URI
= '
https://kyfw.12306.cn/otn/leftTicket/init
'

LOGIN_URI
= '
https://kyfw.12306.cn/otn/login/init
'

MY_URI
= '
https://kyfw.12306.cn/otn/index/initMy12306
'

LOGIN
= u'
登錄
'

from
splinter.browser import
Browser

from
time import
sleep

import
traceback

TICKET_URI
= '
https://kyfw.12306.cn/otn/leftTicket/init
'

LOGIN_URI
= '
https://kyfw.12306.cn/otn/login/init
'

MY_URI
= '
https://kyfw.12306.cn/otn/index/initMy12306
'

LOGIN
= '
login_user
'

def
login():
brw.find_element_by_id(LOGIN).click()
sleep(
3)

uname
= '123456789
@qq.com
'

pwd
= 'xxxyyyzzz
'

brw.find_element_by_id(
'
username
'
).send_keys(uname)
sleep(
1)
brw.find_

熱點內容
mad加密 發布:2025-07-16 01:52:12 瀏覽:423
linux64位內存 發布:2025-07-16 01:02:36 瀏覽:960
壓縮衣尺碼表 發布:2025-07-16 00:47:33 瀏覽:640
安卓恢復了出廠怎麼找回照片 發布:2025-07-16 00:43:56 瀏覽:933
為什麼說伺服器已停止響應 發布:2025-07-16 00:29:36 瀏覽:391
python判斷字元串是否為空 發布:2025-07-16 00:21:47 瀏覽:210
安卓轉蘋果用什麼軟體 發布:2025-07-16 00:21:45 瀏覽:628
安卓官服如何登ios 發布:2025-07-16 00:21:32 瀏覽:624
天龍搶店腳本 發布:2025-07-16 00:14:47 瀏覽:958
華為榮耀存儲卡 發布:2025-07-16 00:10:40 瀏覽:659