我得到的數據以HTML表格形式從外部來源 -遍歷Python字典只檢索所需的行
from xml.etree import ElementTree as ET
s = """<table>
<tr><th>Release</th><th>REFDB</th><th>URL</th></tr>
<tr><td>3.7.3</td><td>12345</td><td>http://google.com</td></tr>
<tr><td>3.7.4</td><td>456789</td><td>http://foo.com</td></tr>
</table>
"""
用於轉換HTML表格字典
table = ET.XML(s)
rows = iter(table)
headers = [col.text for col in next(rows)]
for row in rows:
values = [col.text for col in row]
out = dict(zip(headers, values))
現在我的預期輸出如下所示,我將通過命令行參數傳遞Release版本。 $蟒蛇myscript.py 3.7.3(我有這樣的代碼) 我找過當找到特定的發行版本的字典解決循環 - 在我的情況下,它是3.7.3
Release Version - 3.7.3
REFDB - 12345
URL - http://google.com
'''out'''只包含最後一行* *, – wwii