花了一些时间,能够为 FBO 数据构建解析器函数。怀疑您仍然需要它,但也许这会对其他人有所帮助。
def fbo_parser(fbo):
split_fbo = fbo.split('<PRESOL>')
n_ops = len(split_fbo)
all_ops_dict = {}
for i in range(1, n_ops):
strings = fbo.split('<PRESOL>')[i].replace('</PRESOL>', '')
strings = strings.split('<')
lists = [x.split('>') for x in strings]
opp_dict = {}
desc_count = 0
desc = ['OpDesc', 'URL_Desc', 'EMAIL_Desc']
for ii in lists:
if len(ii) == 2:
if ii[0] == 'DESC':
#TODO: Figure out a better name for the duplicate DESC
ii[0] = ii[0] + str(desc_count)
desc_count += 1
opp_dict[ii[0]] = ''.join([x for x in filter(None, ii[1].split('\\n'))])
all_ops_dict[i] = opp_dict
return all_ops_dict
f = open('FBOFeed19991231', 'rb')
fbo = str(f.read())
fbop = fbo_parser(fbo)
fbop[68]
RETURNS:>>
{'ADDRESS': 'Christel.Wittmer@ramstein.af.mil',
'AGENCY': 'Department of the Air Force',
'CLASSCOD': '32',
'CONTACT': 'Christel Wittmer, Ms., Phone (49) 631 3539 174, Fax (49) 631 3539 158, Email Christel.Wittmer@ramstein.af.mil - Ursula Nabinger, Ms., Phone (49) 631 3539 178, Fax (49) 631 3539 158, Email Ursula.Nabinger@ramstein.af.mil',
'DATE': '0720',
'DESC0': 'WORKBENCH FOR VEHICLE MAINTENANCE,2 METER LONG, TOP IS METAL COVERWERKBANK, 2 METER LANG, SCHICHSTOFF OEL AND FEUCHTIGKEITSBESTAENDIG (22EA/STCK)WORKBENCH FOR VEHICLE MAINTENANCE, 2 METER LONG TOP CONSISTS 40 MM TICK WOODWERKBANK, 2 METER LANG ARBEITSPLATTE HOLZ MEHRSCHICHTVERLEIMTESBUECHENHOLZ (22EA/STCK)FOR MORE INFO CALL MRS WITTMER 0631-3539-174!',
'DESC1': 'Link to FedBizOpps document.',
'DESC2': 'Christel Wittmer',
'EMAIL': '',
'LINK': '',
'LOCATION': '700 CONS',
'OFFADD': 'United States Air Force, United States Air Force Europe, Rhine Ordnance Barracks, USAFE CONS, UNIT 3115, Germany, . 09094-3115',
'OFFICE': 'United States Air Force Europe',
'RESPDATE': '073099',
'SOLNBR': 'F61521-99T0607',
'SUBJECT': 'WORKBENCH FOR VEHICLE MAINTENANCE',
'URL': 'http://www.fbo.gov/spg/USAF/USAFE/ROB/F61521-99T0607/listing.html',
'YEAR': '99',
'ZIP': '09021'}