def policy_info(policyno, session=None): try: if session is None: session = get_cjbx_session() url = "http://32.0.192.232:88/sinoiais/insurance/viewIAPMMain.do?riskType=2&confirmSequenceNo=" + policyno r = session.get(url, headers=headers) return parse_insuranceType(r.text) except Exception as e: log.error(e) import traceback log.error(traceback.format_exc()) return {}
def check_session(): #第二次登陆之后请求修改密码页面保持内部 from request_cjbx.login import get_cjbx_session, login_cjbx headers = se.headers session = get_cjbx_session() url = "http://32.0.192.232:88/sinoiais/modifyPuTongPassword.do" rsp = session.get(url=url, headers=headers) if rsp.url == u'http://32.0.192.232:88/sinoiais/modifyPuTongPassword.do' and u"Session超时" not in rsp.text: print(rsp.status_code) print("session is alive") else: login_cjbx()
def query_car(car_num, session=None, licensetype="02"): url = "http://32.0.192.232:88/sinoiais/showall/query.do?dimensionSelect=03" if session == None: session = get_cjbx_session() car_num = quote(car_num.encode("GB2312")) # print car_num data = "queryLicensetype=&queryCredentialcode=&queryChecked=&policyNo=&vin=&licensetype={1}&carmark={0}&credentialcode=01&credentialno=&cacciid=&taccidt=&dname=&lastNo=&CheckboxGroup1=02&CheckboxGroup1=03&CheckboxGroup1=04&CheckboxGroup1=08&CheckboxGroup1=05&CheckboxGroup1=07&CheckboxGroup1=09".format( car_num, licensetype) headers['Content-Type'] = "application/x-www-form-urlencoded" r = session.post(url=url, data=data, headers=headers) return r.text
def cjbx_start(palte_number, licensetype="02"): try: session = get_cjbx_session() out1 = query_detail(palte_number, session=session, licensetype=licensetype) if out1 != 0: # 获取车辆详细信息 html = query_car(palte_number, session=session, licensetype=licensetype) alldt = parse_query_all(html) alldt['CAR_INFO'] = out1 # 取出前两条保险详情 if len(alldt) != 0 and len(alldt['SY']) != 0: if len(alldt['SY']) > 1: g1 = gevent.spawn(policy_info, alldt['SY'][0]['INSURE_CODE'], session) g2 = gevent.spawn(policy_info, alldt['SY'][1]['INSURE_CODE'], session) gevent.joinall([g2, g1]) alldt['SY'][0]['INSURANCE_TYPE'] = g1.value.get( 'insuranceType', {}) alldt['SY'][0]['INFO'] = g1.value.get('Info', {}) alldt['SY'][1]['INSURANCE_TYPE'] = g2.value.get( 'insuranceType', {}) alldt['SY'][1]['INFO'] = g2.value.get('Info', {}) else: insuranceType = policy_info(alldt['SY'][0]['INSURE_CODE'], session=session) alldt['SY'][0]['INSURANCE_TYPE'] = insuranceType.get( 'insuranceType', {}) alldt['SY'][0]['INFO'] = insuranceType.get('Info', {}) mg_update_insert('InsuranceInfo', {'BODY.PALTE_NO': palte_number}, alldt) mydata = parse_body(alldt) log.info(json.dumps(mydata, ensure_ascii=False)) return mydata else: log.error(u"未查询到用户信息 %s " % palte_number) return 0 except Exception, e: log.error(e) log.error(traceback.format_exc()) return 0
def query_detail(PLATE_NUMBER, session=None, licensetype="02"): if session is None: session = get_cjbx_session() if "挂" in PLATE_NUMBER: type = "%B9%D2%B3%B5%BA%C5%C5%C6" # 挂车号牌 elif licensetype == "01": type = "%B4%F3%D0%CD%C6%FB%B3%B5%BA%C5%C5%C6" # 大型汽车 else: type = "%D0%A1%D0%CD%C6%FB%B3%B5%BA%C5%C5%C6" # 小型汽车 url = "http://32.0.192.232:88/sinoiais/carowner/viewJGCarOwner.do?carmark=" + quote( PLATE_NUMBER.encode("gb2312")) + "&vehicletype=" + type r = session.get(url, headers=headers) html = r.text data = parse_car_detail(html) if data != 0: # del_car(PLATE_NUMBER) # sql_add_car2(data) return data else: return 0
# del_car(PLATE_NUMBER) # sql_add_car2(data) return data else: return 0 # 保单号 查询保险组合 def policy_info(policyno, session=None): try: if session is None: session = get_cjbx_session() url = "http://32.0.192.232:88/sinoiais/insurance/viewIAPMMain.do?riskType=2&confirmSequenceNo=" + policyno r = session.get(url, headers=headers) return parse_insuranceType(r.text) except Exception as e: log.error(e) import traceback log.error(traceback.format_exc()) return {} if __name__ == "__main__": import re import json session = get_cjbx_session() ss = policy_info('V0201PAIC320017001489495565156', session) print json.dumps(ss, ensure_ascii=False)