【问题标题】:Extraxt URL from response.text()从 response.text() 中提取 URL
【发布时间】:2021-04-29 06:22:41
【问题描述】:

我想从以下响应(查找)中提取结果的 id 而不是目标(79 和 12),它是目标的 url。

发现:

{"count":87,
   
   "results":[
      {
         "id":79,
         "target":
             {
                 {"id":567,"url":"https://demo.com
",.....},
          "(...)"
         ,
         "id":12,
         "target":
         
          "(...)"
         ,
         "id":32,
         "target":
          "(...)"
         ,"(....)"
}
]
}

如何提取这些 id 和 URL 并以 dist 的形式存储?

【问题讨论】:

    标签: python curl python-requests libcurl


    【解决方案1】:

    您的示例代码的语法不正确。假设results下的数据是字典列表,可以使用dict理解:

    urls = {i["id"]: i["target"]["site"]["url"] for i in findings["results"]}
    

    【讨论】:

      【解决方案2】:

      使用python dictionary comprehension

      new_dict = {i["id"]: i['target']["site"]["url"] for i in finding["results"]}
      

      【讨论】:

        猜你喜欢
        • 2021-07-22
        • 2015-03-20
        • 2016-11-26
        • 1970-01-01
        • 1970-01-01
        • 2016-09-15
        • 2011-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多