From 75da2b8c341b2948a91241b26614dda1b0fabb1c Mon Sep 17 00:00:00 2001 From: "xianping.wen" <931128603@qq.com> Date: Tue, 10 Sep 2019 13:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2302?= =?UTF-8?q?=EF=BC=8Cversion=201.1.109?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TickerConfig.py | 20 +++++++++----------- config/getCookie.py | 5 +++++ config/urlConf.py | 2 +- init/login.py | 2 +- init/select_ticket_info.py | 6 ++++-- inter/Query.py | 1 + myUrllib/httpUtils.py | 5 ++++- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/TickerConfig.py b/TickerConfig.py index c48fbaa..8fa8d6d 100644 --- a/TickerConfig.py +++ b/TickerConfig.py @@ -6,17 +6,16 @@ # 刷票模式:1=刷票 2=候补+刷票 TICKET_TYPE = 2 + # 出发日期(list) "2018-01-06", "2018-01-07" STATION_DATES = [ - "2019-09-30" + "2019-09-20" ] # 填入需要购买的车次(list),"G1353" STATION_TRAINS = [ "", - "", ] - # 出发城市,比如深圳北,就填深圳就搜得到 FROM_STATION = "" @@ -46,7 +45,6 @@ IS_MORE_TICKET = True # - "李四" TICKET_PEOPLES = [ "", - "", ] # 12306登录账号 @@ -81,13 +79,12 @@ EMAIL_CONF = { "host": "", } -# 是否开启 server酱 微信提醒, 使用前需要前往 http://sc.ftqq.com/3.version 扫码绑定获取 SECRET 并关注获得抢票结果通知的公众号 -SERVER_CHAN_CONF = { - "is_server_chan": False, - "secret": "" +# 是否开启 pushbear 微信提醒, 使用前需要前往 http://pushbear.ftqq.com 扫码绑定获取 send_key 并关注获得抢票结果通知的公众号 +PUSHBEAR_CONF = { + "is_pushbear": False, + "send_key": "" } - # 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭 IS_CDN = 1 @@ -108,10 +105,11 @@ IS_PROXY = 0 # 预售放票时间, 如果是捡漏模式,可以忽略此操作 OPEN_TIME = "13:00:00" + # 1=使用selenium获取devicesID # 2=使用网页端/otn/HttpZF/logdevice获取devicesId,这个接口的算法目前可能有点问题,如果登录一直302的请改为配置1 COOKIE_TYPE = 1 -# 如果COOKIE_TYPE=1,则需配置chromeDriver路径,下载地址http://chromedriver.storage.googleapis.com/index.html +# 如果COOKIE_TYPE=2,则需配置chromeDriver路径,下载地址http://chromedriver.storage.googleapis.com/index.html # chromedriver配置版本只要和chrome的大版本匹配就行 CHROME_PATH = "/Users/wenxianping/Downloads/chromedriver" @@ -128,4 +126,4 @@ PASSENGER_TICKER_STR = { } # 软件版本 -RE_VERSION = "1.1.108" +RE_VERSION = "1.1.109" diff --git a/config/getCookie.py b/config/getCookie.py index b5e961e..cc664bc 100644 --- a/config/getCookie.py +++ b/config/getCookie.py @@ -27,6 +27,7 @@ def getDrvicesID(session): print(f"获取cookie: {cookies}") if cookies: session.httpClint.set_cookies(cookies) + session.cookies = cookies print("cookie获取完成") elif TickerConfig.COOKIE_TYPE is 2: request_device_id(session) @@ -48,6 +49,10 @@ def request_device_id(session): 'RAIL_EXPIRATION': result.get('exp'), 'RAIL_DEVICEID': result.get('dfp'), }]) + session.cookies = [{ + 'RAIL_EXPIRATION': result.get('exp'), + 'RAIL_DEVICEID': result.get('dfp'), + }] except: return False diff --git a/config/urlConf.py b/config/urlConf.py index e23eca9..94eebc4 100755 --- a/config/urlConf.py +++ b/config/urlConf.py @@ -34,7 +34,7 @@ urls = { "Referer": "https://kyfw.12306.cn/otn/resources/login.html", "Host": "kyfw.12306.cn", "Content-Type": 1, - "re_try": 2, + "re_try": 10, "re_time": 1, "s_time": 0.5, "is_logger": True, diff --git a/init/login.py b/init/login.py index fe2aedd..2d05008 100755 --- a/init/login.py +++ b/init/login.py @@ -128,7 +128,7 @@ class GoLogin: login_num = 0 while True: if loginConf(self.session): - self.auth() + # self.auth() result = getPassCodeNewOrderAndLogin1(session=self.session, imgType="login") if not result: diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index 3f3b00c..d8473ef 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -41,7 +41,8 @@ class select: self.urls = urlConf.urls self.login = GoLogin(self, TickerConfig.IS_AUTO_CODE, self.auto_code_type) self.cdn_list = [] - self.queryUrl = "leftTicket/queryT" + self.cookies = "" + self.queryUrl = "leftTicket/queryA" self.passengerTicketStrList = "" self.passengerTicketStrByAfterLate = "" self.oldPassengerStr = "" @@ -111,6 +112,7 @@ class select: def cdn_req(self, cdn): for i in range(len(cdn) - 1): http = HTTPClient(0) + http.set_cookies(self.cookies) urls = self.urls["loginInitCdn"] http._cdn = cdn[i].replace("\n", "") start_time = datetime.datetime.now() @@ -142,11 +144,11 @@ class select: raise ticketConfigException(u"cdn列表为空,请先加载cdn") def main(self): - self.cdn_certification() l = liftTicketInit(self) l.reqLiftTicketInit() getDrvicesID(self) self.call_login() + self.cdn_certification() check_user = checkUser(self) t = threading.Thread(target=check_user.sendCheckUser) t.setDaemon(True) diff --git a/inter/Query.py b/inter/Query.py index 7636c09..eb33d79 100644 --- a/inter/Query.py +++ b/inter/Query.py @@ -18,6 +18,7 @@ class query: ticke_peoples_num, station_dates=None, ): self.session = session self.httpClint = HTTPClient(TickerConfig.IS_PROXY) + self.httpClint.set_cookies(self.session.cookies) self.urls = urlConf.urls self.from_station = from_station self.to_station = to_station diff --git a/myUrllib/httpUtils.py b/myUrllib/httpUtils.py index 9bc7076..e234926 100755 --- a/myUrllib/httpUtils.py +++ b/myUrllib/httpUtils.py @@ -1,5 +1,6 @@ # -*- coding: utf8 -*- import json +import random import socket from collections import OrderedDict from time import sleep @@ -14,7 +15,9 @@ def _set_header_default(): # header_dict["Accept"] = "application/json, text/plain, */*" header_dict["Accept-Encoding"] = "gzip, deflate" header_dict[ - "User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + "User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0." + str( + random.randint( + 5000, 7000)) + ".0 Safari/537.36" header_dict["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" header_dict["Origin"] = "https://kyfw.12306.cn" header_dict["Connection"] = "keep-alive" -- GitLab