我正在试图获得String" W:_fdsw \ Projects \ HIL \ releases \ release_9_1_0 \ Config \ CDNG \ UX_EF_TSHIL \ UX_EF_TSHIL.CDP"并使用minidom将其保存在变量中
<TOOL id="CONTROLDESKNG" xsi:type="tool">
<TOOL-HOST xsi:type="unicode">tsp:QMUC633107:5018</TOOL-HOST>
<TOOL-NAME xsi:type="unicode">CONTROLDESKNG</TOOL-NAME>
<START-OPTION xsi:type="integer">0</START-OPTION>
<START-PRIORITY xsi:type="integer">0</START-PRIORITY>
<SETTINGS xsi:type="dynamicPropertySet">
<PROPERTY format-rev="1" name="ExpName" propertyType="string" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">K53MU</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="ModelDir" propertyType="uri" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">W:\_fdsw\Projects\HIL\releases\release_9_1_0\Config\CDNG\UX_EF_TSHIL\Variable Descriptions\UX_EF_TSHIL.sdf(#14)</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="PrjFile" propertyType="uri" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">W:\_fdsw\Projects\HIL\releases\release_9_1_0\Config\CDNG\UX_EF_TSHIL\UX_EF_TSHIL.CDP</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="RecordingFormat" propertyType="string" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">MDF</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="ToolState" propertyType="string" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">Online</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="VersionCDNG" propertyType="string" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">5.5</VALUE>
</PROPERTY>
<PROPERTY format-rev="1" name="VersionHILAPI" propertyType="string" readonly="false" xsi:type="_property">
<VALUE xsi:type="unicode">2015-B</VALUE>
</PROPERTY>
</SETTINGS>
</TOOL>
我的代码是:
xmldoc = minidom.parse('C:\Users\qxn5622\Desktop\EF10018\DEFAULT.tbc')
propertyList = xmldoc.getElementsByTagName('PROPERTY')
for prop in propertyList:
if prop.attributes["name"].value == "ModelDir":
myString = prop.getElementsByTagName("VALUE").value
我认为问题在于我试图得到的元素没有任何ID。 有人能帮助我吗?
答案 0 :(得分:1)
这可能会有所帮助
W:\_fdsw\Projects\HIL\releases\release_9_1_0\Config\CDNG\UX_EF_TSHIL\UX_EF_TSHIL.CDP
<强>输出:强>
soup.find_all(has_class_but_no_id)
# [<p class="title"><b>The Dormouse's story</b></p>,
# <p class="story">Once upon a time there were...</p>,
# <p class="story">...</p>]