import traceback class Properties(object): def __init__(self, fileName): self.fileName = fileName self.properties = {} def __getDict(self, strName, dictName, value): if(strName.find('.') > 0): k = strName.split('.')[0] dictName.setdefault(k, {}) return self.__getDict(strName[len(k) + 1:], dictName[k], value) else: dictName[strName] = value return def getProperties(self): pro_file = open(self.fileName, 'Ur', encoding='utf-8') for line in pro_file.readlines(): line = line.strip().replace('\n', '') if line.find("#") != -1: line = line[0:line.find('#')] if line.find('=') > 0: strs = line.split('=') strs[1] = line[len(strs[0]) + 1:] self.__getDict(strs[0].strip(), self.properties, strs[1].strip()) return self.properties
=============
import os os.system("testAccountGrant.1.py") os.system("testApointmentSubmit.1.py") os.system("testMedicalMealDetail.1.py") os.system("testNbYbtYYXinxi.1.py") os.system("testQueryTbDicTjdcList.1.py") os.system("testQueryTbDicTjxmList.1.py") os.system("testGetPublicpharmacy.1.py") os.system("pause") ===============
import os import requests import json from Util import Properties print('########[agreementSign]################ * start') properties = Properties("./global.properties").getProperties() headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', 'Accept': 'text/html;q=0.9,*/*;q=0.8,application/json, text/plain, */*', # 'Accept': 'text/html;q=0.9,*/*;q=0.8', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding': 'gzip', 'Connection': 'close', # 'content-type': 'application/json;charset=utf-8', 'Referer': None # 注意如果依然不能抓取的话,这里可以设置抓取网站的host } def data1(): with open('./json/addRenewalInfo.1.json', encoding='utf-8') as json_file: data = json.load(json_file) return data print("***执行接口>>>>>", properties['addRenewalInfo'], '\n【请求参数】', data1()) files = {'imgSign': ('1.jpg', open( 'C:\\Users\\Administrator\\Desktop\\imgs\\2.jpg', 'rb'), 'image/jpg'), 'xxx': ('1.jpg', open( 'C:\\Users\\Administrator\\Desktop\\imgs\\3.jpg', 'rb'), 'image/jpg')} r1 = requests.post(properties['addRenewalInfo'], data=data1(), files=files, headers=headers) r1.encoding = 'utf-8' print('【响应】', r1.text)