def get_gt_challenge(self, t=1): if t == 15: raise Exception(u'获取不到challenge') self.info(u'第%d次获取challenge。。。' % t) ts_1 = TimeUtils.get_cur_ts_mil() url_1 = "http://sd.gsxt.gov.cn/pub/geetest/register/%s?_=%s" % (TimeUtils.get_cur_ts_mil(), ts_1) r_1 = self.get_request(url_1) try: self.challenge = str(json.loads(r_1.text)['challenge']) self.gt = str(json.loads(r_1.text)['gt']) except: self.get_gt_challenge(t+1)
def get_gt_challenge(self): url_1 = 'http://bj.gsxt.gov.cn/pc-geetest/register?t=%s' % TimeUtils.get_cur_ts_mil( ) # print url_1 r_1 = self.get_request(url_1) self.challenge = str(json.loads(r_1.text)['challenge']) self.gt = str(json.loads(r_1.text)['gt'])
def break_params(self): bg_img = self.down_geetest_img(self.bg_url) slice_img = self.down_geetest_img(self.slice_url) fullbg_path = os.path.join(os.path.dirname(__file__), '../data/fullbg/' + self.fullbg_url.split('/')[-1]) if not os.path.exists(fullbg_path): print u'New fullbg image' fullbg_img = self.down_geetest_img(self.fullbg_url) fullbg_img.save(fullbg_path) fullbg_img = Image.open(fullbg_path) distance = GeetestDistanceV2.get_distance(bg_img, fullbg_img, slice_img) # print 'distance->', distance trail_arr = BreakTrail.get_trali_arr(distance) # print 'distance:', distance pass_time = trail_arr[-1][-1] # print trail_arr params = { 'challenge': str(self.challenge), 'gt': str(self.gt), 'userresponse': GeetestParamsBroker.imitate_userrespose(distance, self.challenge), 'passtime': pass_time, 'imgload': random.randint(70, 150), 'aa': GeetestParamsBroker.imitate_aa(trail_arr, self.c, self.s), 'callback': 'geetest_%s' % TimeUtils.get_cur_ts_mil(), } # print json.dumps(params, indent=4) return params, trail_arr[-1][2]
def get_gt_challenge(self): url_1 = "http://zj.gsxt.gov.cn/pc-geetest/register?t=%s" % TimeUtils.get_cur_ts_mil( ) self.info(u'获取gt和challenge...') r_1 = self.get_request(url_1) json_1 = json.loads(r_1.text) self.gt = json_1['gt'] self.challenge = json_1['challenge']
def get_gt_challenge(self): url_1 = "http://www.gsxt.gov.cn/SearchItemCaptcha?v=%s" % TimeUtils.get_cur_ts_mil() # print url_1 self.info(u'**获取gt和challenge...') r_1 = self.get(url_1) json_1 = json.loads(r_1.text) self.gt = json_1['gt'] self.challenge = json_1['challenge']
def refresh_api(self): self.info(u'轨迹有误,刷新极验api...') url_2 = "http://api.geetest.com/refresh.php?" \ "challenge=%s" \ ">=%s" \ "&callback=geetest_%s" % (self.challenge, self.gt, TimeUtils.get_cur_ts_mil()) r_2 = self.get(url_2) # print r_2.text json_2 = json.loads(r_2.text[r_2.text.find('{'):r_2.text.rfind('}') + 1]) self.bg_url = 'http://' + self.static_server + json_2['bg'] self.fullbg_url = 'http://' + self.static_server + json_2['fullbg'] self.slice_url = 'http://' + self.static_server + json_2['slice'] self.challenge = json_2['challenge']
def get_gt_challenge(self, t=0): if t == 15: raise Exception(u'获取gt和challenge失败') url_1 = 'http://hb.gsxt.gov.cn/registerValidate.jspx?t=%s' % TimeUtils.get_cur_ts_mil( ) r_1 = self.get_request(url_1) # print r_1.text, r_1.text.strip().startswith('{'), r_1.text.strip().endswith('}') if r_1.text.strip().startswith('{') and r_1.text.strip().endswith('}'): self.challenge = str(json.loads(r_1.text)['challenge']) self.gt = str(json.loads(r_1.text)['gt']) else: time.sleep(1) self.reset_session() self.get_gt_challenge(t + 1)
def get_tag_a_from_page(self, keyword): cur_ts_mil = TimeUtils.get_cur_ts_mil() yzm_url = "http://qyxy.baic.gov.cn/CheckCodeYunSuan?currentTimeMillis=%s" % cur_ts_mil yzm = self.get_yzm(yzm_url) print 'yzm', yzm check_url = "http://qyxy.baic.gov.cn/login/loginAction!checkCode.dhtml?check_code=%s¤tTimeMillis=%s&random=%s" \ % (yzm, cur_ts_mil, random.randint(10000, 100000)) print check_url r = self.post_request( check_url, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0", "Host": "qyxy.baic.gov.cn", }) print r.text search_url = "http://qyxy.baic.gov.cn/es/esAction!entlist.dhtml?currentTimeMillis=%s&credit_ticket=%s&check_code=%s" % ( cur_ts_mil, self.credit_ticket, yzm) print search_url params = { 'idFlag': 'qyxy', 'module': '', 'queryStr': keyword, 'currentTimeMillis': cur_ts_mil, 'credit_ticket': self.credit_ticket, 'check_code': yzm } print params search_url = "http://qyxy.baic.gov.cn/es/esAction!entlist.dhtml?currentTimeMillis=" + cur_ts_mil + "&credit_ticket=" + self.credit_ticket + "&check_code=" + yzm + "&idFlag=qyxy&module=&queryStr=%E9%94%A4%E5%AD%90%E7%A7%91%E6%8A%80" print search_url r = self.post_request( search_url, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0", "Host": "qyxy.baic.gov.cn", # "Content-Length": "0", # "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", # "Accept-Encoding": "gzip, deflate", # "Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3", # "Connection": "keep-alive", # "Upgrade-Insecure-Requests": "1", # "Referer": "http://qyxy.baic.gov.cn/simple/dealSimpleAction!transport_ww.dhtml?fourth=fourth&sysid=0150008788304366b7d3903b5067bb8c&module=wzsy&styleFlag=sy", }) r.encoding = 'utf-8' print r.text print self.session.cookies
def load_api(self): self.info(u'获取极验api...') ts = TimeUtils.get_cur_ts_mil() url_1 = 'http://api.geetest.com/gettype.php?gt=%s&callback=geetest_%s' % (self.gt, ts) # print 'url_1', url_1 r_1 = self.get(url_1) # print r_1.text # print r_1.text[len('geetest_%s(' % ts):-1] if 'data' in json.loads(r_1.text[len('geetest_%s(' % ts):-1]): path = json.loads(r_1.text[len('geetest_%s(' % ts):-1])['data']['path'] else: path = json.loads(r_1.text[len('geetest_%s(' % ts):-1])['path'] url_2 = "http://api.geetest.com/get.php?" \ "gt=%s" \ "&challenge=%s" \ "&product=%s" \ "&offline=false" \ "&protocol=" \ "&type=slide" \ "&path=%s" \ "&callback=geetest_%s" % (self.gt, self.challenge, self.geetest_product, path, TimeUtils.get_cur_ts_mil()) # print 'url_2', url_2 r_2 = self.get(url_2, headers={}) # print r_2.text json_2 = json.loads(r_2.text[r_2.text.find('{'):r_2.text.rfind('}') + 1]) self.s = json_2['s'] self.c = json_2['c'] if 'staticservers' in json_2: self.static_server = json_2['staticservers'][0] self.bg_url = 'http://' + self.static_server + json_2['bg'] self.fullbg_url = 'http://' + self.static_server + json_2['fullbg'] self.slice_url = 'http://' + self.static_server + json_2['slice'] self.challenge = json_2['challenge'] elif 'static_servers' in json_2: self.static_server = json_2['static_servers'][0] self.bg_url = 'http://' + self.static_server + json_2['bg'] self.fullbg_url = 'http://' + self.static_server + json_2['fullbg'] self.slice_url = 'http://' + self.static_server + json_2['slice'] self.challenge = json_2['challenge'] else: self.session.cookies.clear(domain='api.geetest.com') self.get_gt_challenge() self.load_api()
def get_gt_challenge(self): url_1 = "http://www.jsgsj.gov.cn:58888/province/geetestViladateServlet.json?register=true&t=%s" % TimeUtils.get_cur_ts_mil( ) self.info(u'获取gt和challenge...') r_1 = self.get_request(url_1) json_1 = json.loads(r_1.text) self.gt = json_1['gt'] self.challenge = json_1['challenge']
def get_gt_challenge(self): url_1 = 'http://gd.gsxt.gov.cn/aiccips//verify/start.html?t=%s' % TimeUtils.get_cur_ts_mil( ) r_1 = self.get_request(url_1) self.challenge = str(json.loads(r_1.text)['challenge'])