【问题标题】:Cannot get specific value attribute from list of value attributes无法从值属性列表中获取特定值属性
【发布时间】:2017-12-14 09:17:20
【问题描述】:

我有一个需要控制的复选框,但首先我需要查看它是否被选中,然后再继续。当我单击复选框时,唯一似乎发生变化的 HTML 是:-

<input type="hidden" class="final-json" name="defaults" value="
{"force_change_projects":{"enabled":false},"coverage":
{"regions":"coding_only","buffer_length":20},"acmg":
{"enabled":true},"double_user_check":{"enabled":true},"other_coverage":
{"default_depth":20,"coverage":[20],"locked":false}}">

我需要的值属性是"double_user_check":{"enabled":true},每次单击复选框时,启用状态都会相应更改。我可以获取整个 value 属性,但我只需要从中获取 double_user_check 属性。我只是似乎无法得到它。

所以我需要检查double_user_check 值的启用/禁用状态。

【问题讨论】:

    标签: python html google-chrome webdriver


    【解决方案1】:

    您可以使用python2 中的simplejson 库或python3 中的json

    使用json.loads(json_data) 将json 变成python 对象。 然后使用double_user_checkenabled 作为新python 对象的索引。

    try:
        import simplejson as json
    except ImportError:
        import json
    
    json_data = """{"force_change_projects":{"enabled":false},"coverage":
    {"regions":"coding_only","buffer_length":20},"acmg":
    {"enabled":true},"double_user_check":{"enabled":true},"other_coverage":
    {"default_depth":20,"coverage":[20],"locked":false}}"""
    
    data = json.loads(json_data)
    enabled = data['double_user_check']['enabled']
    
    print enabled
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      相关资源
      最近更新 更多