花了一些時間,並能夠建立一個解析器函數的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': '[email protected]',
'AGENCY': 'Department of the Air Force',
'CLASSCOD': '32',
'CONTACT': 'Christel Wittmer, Ms., Phone (49) 631 3539 174, Fax (49) 631 3539 158, Email [email protected] - Ursula Nabinger, Ms., Phone (49) 631 3539 178, Fax (49) 631 3539 158, Email [email protected]',
'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'}
當我輸出testall它給了我[] – Jared 2013-03-15 02:39:08
這似乎不忍心XML任何關係(這好像是你自己發明的一種標記語言)。你爲什麼把它標記爲XML? – 2013-03-15 09:03:41
我不確定它是否是某種我只是不理解的XML。 – Jared 2013-03-15 14:47:53