Pytronik
Pytronik

Reputation: 69

Scraping data from json which is in "2nd line"

Good evening,

I want to scrape the testid. What I tried and which isn't working. What am I doing wrong?

Json = json.loads(info.content)
aba = Json['checkout']['line_items'].get("testid")
infocontent = 
{
   "checkout":{
      "completed_at":null,
      "created_at":"2020-02-27T17:43:50+01:00",
      "line_items":[
         {
            "id":"538af6bda25ea2ba30811ca527631cc6",
            "key":"538af6bda25ea2ba30811ca527631cc6",
            "auth":4462126596176,
            "testid":31830643277904,
          }]
}

Upvotes: 1

Views: 82

Answers (1)

user12975054
user12975054

Reputation:

The value of line_items is a list of objects, albeit there is only one object in the list. You need to get the first item in the list before you can use get on it.

aba = Json['checkout']['line_items'][0].get("testid")

Upvotes: 1

Related Questions