python json的相关操作
巴扎黑
巴扎黑 2017-04-17 17:51:38
0
1
331

第一步
(已经得到data)

{
"data": [
      "id": "123456",
      "driver": "2016-03-28",
      "phone": "13800138000",
      "type": "A",
    },
    {
      "id": "456789",
      "driver": "2016-03-28",
      "phone": "13800138111",
      "type": "B",
    },
    {
      "id": "13579",
      "driver": "2016-03-28",
      "phone": "138001382222",
      "type": "B",
    }
  ]
}

第二步
只需要输出data数据中的"phone"
13800138000
13800138111
138001382222

第三步
网址如下

http://httpbin.org/response-headers?Content-Type=text%2Fplain%3B+charset%3DUTF-8&phone=phone

phone = phone
遍历第二步的phone 替换这个phone
进行批量下载json

应该是需要
import json
import requests
import os

巴扎黑
巴扎黑

membalas semua(1)
大家讲道理
import json

import requests

data = '''
{
"data": [
{
      "id": "123456",
      "driver": "2016-03-28",
      "phone": "13800138000",
      "type": "A"
    },
    {
      "id": "456789",
      "driver": "2016-03-28",
      "phone": "13800138111",
      "type": "B"
    },
    {
      "id": "13579",
      "driver": "2016-03-28",
      "phone": "138001382222",
      "type": "B"
    }
  ]
}'''
url_template = 'http://httpbin.org/response-headers?Content-Type=text%2Fplain%3B+charset%3DUTF-8&phone={phone}'
json_loads = json.loads(data)
for item in json_loads["data"]:
    phone = item["phone"]
    url = url_template.format(phone=phone)
    print requests.get(url).text

Perhatikan bahawa data json anda tidak mematuhi spesifikasi json standard Anda harus menggunakan data saya.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan