0
我有下面的XML文檔Python:從XML文檔中獲取某些值的有效腳本?
<data>
<point address="com.example.www" time="Jul 30, 2013 10:02:56 PM" protocol="http" type="2" body="404 Not Found" name="Example Site" />
<point address="com.example.test" time="Jul 29, 2013 07:45:03 AM" protocol="https" type="2" body="This is a test" name="Test.example" />
.......
</data>
我用下面的Python代碼:
import libxml2
def ReadValue(pn, dt):
return [attr.content for attr in input_file.xpathEval("/data/point[@protocol='%s']/@%s" % (pn, dt))]
protocol = ["http", "https"]
data_type = ["body", "type", "time", "name"]
for i in protocol:
for j in data_type:
print ReadValue(i, j)
exit()
我懷疑ReadValue
是瓶頸時,我分析了20萬組的標籤。它運行的非常慢,即使我在運行時無法按Ctrl-C腳本。有沒有比使用上面提到的代碼更好的實現?
謝謝