2017-06-15 13 views
-3
<lib name="atl80.dll" bl="0"> 
    <fcts> 
    <fct od="15" bl="0">AtlComModuleGetClassObject</fct> 
    <fct od="18" bl="1">AtlComModuleRegisterServer</fct> 
    <fct od="22" bl="1">AtlComModuleUnregisterServer</fct> 
    <fct od="23" bl="1">AtlUpdateRegistryFromResourceD</fct> 
    <fct od="30" bl="0">AtlComPtrAssign</fct> 
    <fct od="31" bl="0">AtlComQIPtrAssign</fct> 
    <fct od="32" bl="0">AtlInternalQueryInterface</fct> 
    <fct od="34" bl="0">AtlGetVersion</fct> 
    <fct od="58" bl="0">AtlModuleAddTermFunc</fct> 
    <fct od="61" bl="1">AtlCreateRegistrar</fct> 
    <fct od="64" bl="0">AtlCallTermFunc</fct> 

やあみんな、私はxmlファイルを解析したい、それはコンテンツとエキスだ反復: [1] libの名前 BL = 1解析xmlファイルパイソン

場合は、[2] FCTタグテキスト を抽出

xmlを解析してこの情報を抽出する必要がありますか?

ありがとうございました!ここで

+0

何を試してみましたか? –

+1

あなたが最初に試したこと、できなかったことを示してください。 – wolfsgang

+0

pythonモジュールを使用する** lxml **または** bs4 ** – Stack

答えて

0

は一例であり、あなたは

html = """<lib name="atl80.dll" bl="0"> 
    <fcts> 
    <fct od="15" bl="0">AtlComModuleGetClassObject</fct> 
    <fct od="18" bl="1">AtlComModuleRegisterServer</fct> 
    <fct od="22" bl="1">AtlComModuleUnregisterServer</fct> 
    <fct od="23" bl="1">AtlUpdateRegistryFromResourceD</fct> 
    <fct od="30" bl="0">AtlComPtrAssign</fct> 
    <fct od="31" bl="0">AtlComQIPtrAssign</fct> 
    <fct od="32" bl="0">AtlInternalQueryInterface</fct> 
    <fct od="34" bl="0">AtlGetVersion</fct> 
    <fct od="58" bl="0">AtlModuleAddTermFunc</fct> 
    <fct od="61" bl="1">AtlCreateRegistrar</fct> 
    <fct od="64" bl="0">AtlCallTermFunc</fct> 

""" 


from bs4 import BeautifulSoup as b 

soup = b(html, 'html.parser') 
fct = soup.find_all(bl="1") 
#get parent name 
parent_name = fct[0].parent.parent['name'] 
# get all fct tag text 
fct = [i.text for i in fct] 

print(parent_name) 
print(fct)