package com.offcn.TestUnti;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.testng.annotations.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by puhui on 2017/1/9.
 */
public class GetTaoBaoCookies {

    public static List<Map<String, String>> initCookies(FileReader fr) throws IOException {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        int m = 1;
        while ((line = br.readLine()) != null) {
            System.err.println("第" + m + "行");
            m++;
            String[] arrs = line.split("\t");
            Map<String, String> map = new HashMap<>();
            map.put("path", arrs[2]);
            map.put("name", arrs[arrs.length - 2]);
            map.put("value", arrs[arrs.length - 1]);
            map.put("domain", arrs[0]);
            list.add(map);
        }
        return list;

    }

    @Test
    public void getcookies() throws IOException {
        FileReader fr = new FileReader("d:/cookies.txt");
        List<Map<String, String>> list = initCookies(fr);
        System.out.println();
        Map a = new HashMap();
        a.put("xx", JSONArray.fromObject(list));
        System.out.println(JSONObject.fromObject(a));
    }
}
