[英]Python Beautifulsoup : how to find a tag by attribute value without knowing corresponding attribute name?
[英]How to find value based on key without knowing section name
如果我僅知道B的值(並且現在不知道在哪個部分可以找到B的值),是否有辦法獲得下面SEC-1的A值?
所以我所知道的是B = XX,我想獲得A值為101。
[SEC-1]
A=101
B=XX
[SEC-2]
A=102
B=YY
這可能會有所幫助。
import configparser
config = configparser.ConfigParser()
config.read(filename)
for ses in config.sections():
if config[ses].get("B") == "XX": #Check if var B has XX
print(config[ses].get("A"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.