2016-03-23 121 views
-1

如何獲得這兩個值utc_last_updated並給出下面的json名稱? 我使用了請求,獲取內容,然後使用BeautifulSoup使其像現在一樣。但是現在我只想提取我所展示的兩個值。如何使用,beautifulsoup和python從此json提取數據?

"data": [ 
     { 
      "scm": "hg", 
      "has_wiki": false, 
      "last_updated": "2016-03-23T14:05:27.433", 
      "no_forks": false, 
      "created_on": "2016-03-18T22:55:52.705", 
      "owner": "user", 
      "email_mailinglist": "", 
      "is_mq": false, 
      "size": 420034, 
      "read_only": false, 
      "fork_of": null, 
      "mq_of": null, 
      "state": "available", 
      "utc_created_on": "2016-03-18 21:55:52+00:00", 
      "website": "", 
      "description": "", 
      "has_issues": false, 
      "is_fork": false, 
      "slug": "store", 
      "is_private": true, 
      "name": "store", 
      "language": "python", 
      "utc_last_updated": "2016-03-23 13:05:27+00:00", 
      "no_public_forks": true, 
      "creator": null, 
      "resource_uri": "/1.0/repositories/my_url" 
     }, 
     { 
      "scm": "hg", 
      "has_wiki": false, 
      "last_updated": "2016-03-18T12:26:22.261", 
      "no_forks": false, 
      "created_on": "2016-03-18T12:19:08.262", 
      "owner": "user", 
      "email_mailinglist": "", 
      "is_mq": false, 
      "size": 173137, 
      "read_only": false, 
      "fork_of": null, 
      "mq_of": null, 
      "state": "available", 
      "utc_created_on": "2016-03-18 11:19:08+00:00", 
      "website": "", 
      "description": "", 
      "has_issues": false, 
      "is_fork": false, 
      "name": 'foo' 
      "is_private": true,, 
      "language": "python", 
      "utc_last_updated": "2016-03-18 11:26:22+00:00", 
      "no_public_forks": true, 
      "creator": null, 
      "resource_uri": "/1.0/repositories/my_rl" 
     }, 

} 我將不勝感激任何幫助。

+0

這是您的充分反應?還是你從HTML文檔中獲得這個? – Gocht

+0

它看起來不像你已正確格式化JSON。 – metersk

+0

嗨,我正在以下:https://answers.atlassian.com/questions/18451025/how-to-hit-bitbucket-api-using-python-requests-module –

回答

4

你已經有了一個JSON響應,不HTML - 與json module解析它:

import json 

data = json.loads(response) 
for item in data["data"]: 
    print(item["utc_last_updated"]) 
+0

我有這種TypeError:JSON對象必須是str,而不是'Response' –

+0

@ SlangI'mmatalk是否使用'requests'?在這種情況下,你甚至可以這樣做:'data = response.json()'。 – alecxe

+0

是的,我正在使用請求,但是當我做這個data = response.json()時,json是無效的。我遵循這個:https://answers.atlassian.com/questions/18451025/how-to-hit-bitbucket-api-using-python-requests-module和我的requests.get後我用美麗,然後我想那些值提取。 –

相關問題