def get_session(username, password, relogin=False): ''' 获取一个 requests 的 session 对象,改对象已经登录过,cookie里面保留了登录之后的信息 :return: ''' session = None if not session: session = login(username, password) if relogin: session = login(username, password) return session
def main(): # mysql connect = pymysql.connect(**MYSQL_CONF_DEV) cursor = connect.cursor() cursor2 = connect.cursor() # get for i in user_pass_list: name = i[0] print('正在抓取: {}'.format(name)) username = i[1] password = i[2] session = login(username, password) result = get_department(session=session) sql = 'INSERT INTO sjzq_ks (sqbm,bm,mc,state,prj) VALUES (%s,%s,%s,%s,%s)' for i in result['pageResult']['pages']: ORG_NAME = i['ORG_NAME'] sql2 = 'SELECT BM FROM sjzq_jg WHERE MC=%s' cursor2.execute(sql2, (ORG_NAME)) result = cursor2.fetchone() BM = result['BM'] DEPT_ID = i['DEPT_ID'] DEPT_NAME = i['DEPT_NAME'] state = 1 prj = 1 cursor.execute(sql, (BM, DEPT_ID, DEPT_NAME, state, prj)) connect.commit() connect.close()
def main(): # mysql connect = pymysql.connect(**MYSQL_CONF_DEV) cursor = connect.cursor() # get session = login('xingjinhua', '123456789') r = get_organization(session) children = r['children'][0]['children'][0]['children'] type_map = { "盟/市卫生局": '1', "区/县卫生局": '2', "卫生服务中心/卫生院": '4', "卫生服务站/卫生室": '5', } sql = 'INSERT INTO sjzq_jg (bm,mc,sjbm,state,lx,prj) VALUES (%s,%s,%s,%s,%s,%s)' for i in children: SJBM = '152222000' BM = i['orgCode'] if BM.startswith('22'): BM = '1522' + BM MC = i['orgName'] LX = type_map[i['orgType']] children = i['children'] cursor.execute(sql, (BM, MC, SJBM, '1', LX, '1')) if children: for ii in children: SJBM = BM BM = ii['orgCode'] if BM.startswith('22'): BM = '1522' + BM MC = ii['orgName'] LX = type_map[ii['orgType']] cursor.execute(sql, (BM, MC, SJBM, '1', LX, '1')) connect.commit() connect.close()
def main(): # Mysql connect = pymysql.connect(**MYSQL_CONF_DEV) cursor = connect.cursor() # 兴安盟县下面的镇列表 session = login('xingjinhua', '123456789') dsnTreeList = get_region_code(session=session, region_code='152222') print(dsnTreeList) sql = 'INSERT INTO sjzq_dq (bm,mc,sjbm,lx,prj) VALUES (%s, %s, %s, %s, %s)' for i in dsnTreeList: town_id = i['id'] town_text = i['text'] cursor.execute(sql, (town_id, town_text, '152222', '5', '1')) dsnTreeList2 = get_region_code(session=session, region_code=town_id) for ii in dsnTreeList2: village_id = ii['id'] village_text = ii['text'] cursor.execute(sql, (village_id, village_text, town_id, '5', '1')) connect.commit() connect.close()
def main(): # mysql connect = pymysql.connect(**MYSQL_CONF_DEV) cursor = connect.cursor() # for for i in user_pass_list: name = i[0] print('正在抓取: {}'.format(name)) username = i[1] password = i[2] session = login(username, password) # get doctor list result = get_doctor(session=session) sql = 'INSERT INTO sjzq_ry (sqbm,bm,mc,xb,lb,ksbm,state,csrq,sfzh,lxdh,prj) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' for i in result['pageResult']['pages']: EMPID = i['EMPID'] # get doctor detail result = get_doctor_detail(session, EMPID) orgUserBean = result['orgUserBean'] sqbm = result['orgCode'] if sqbm.startswith('22'): sqbm = '1522' + sqbm bm = orgUserBean['empId'] mc = orgUserBean['empName'] xb = orgUserBean['sex'] if orgUserBean['sex'] else '0' lb = '1' if orgUserBean['perType'] else '2' ksbm = orgUserBean['deptId'] state = '1' csrq = orgUserBean['birthDate'] sfzh = orgUserBean['idNo'] lxdh = orgUserBean['telNo'] prj = '1' cursor.execute( sql, (sqbm, bm, mc, xb, lb, ksbm, state, csrq, sfzh, lxdh, prj)) connect.commit() connect.close()