Java通过Python实现以图搜图api接口

java请求示例:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.net.URLConnection;
 
public class Example {
	private static String readAll(Reader rd) throws IOException {
		StringBuilder sb = new StringBuilder();
		int cp;
		while ((cp = rd.read()) != -1) {
			sb.append((char) cp);
		}
		return  sb.toString();
	}
	public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		conn.setDoOutput(true);
		conn.setDoInput(true);
		PrintWriter out = new PrintWriter(conn.getOutputStream());
		out.print(body);
		out.flush();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static void main(String[] args) throws IOException, JSONException {
		// 请求示例 url 默认请求参数已经URL编码处理
		String url = "https://api-gw.onebound.cn/taobao/item_search_img/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&imgid=http://g-search3.alicdn.com/img/bao/uploaded/i4/O1CN01IDpcD81zHbpHs1YgT_!!2200811456689.jpg&cat=";
		JSONObject json = getRequestFromUrl(url);
		System.out.println(json.toString());
	}
 
}

响应参数

名称 类型 必须 示例值 描述

title

String 0 亲子装短袖t恤社会人衣服全家装一家三口母子母女纯棉夏装上衣潮 宝贝标题

cid

Int 0 50015374

list_type

String 0 外观相似宝贝 列表类型

pic_url

String 0 //g-search3.alicdn.com/img/bao/uploaded/i4/TB26ry1rBsmBKNjSZFsXXaXSVXa_!!2628705716.jpg 宝贝图片

promotion_price

String 0 38.71 优惠价

price

Float 0 39.50 价格

sales

Int 0 7 销量

num_iid

Bigint 0 575727312808 宝贝ID

sample_id

Bigint 0 1627115368 商品风格标识ID

seller_nick

String 0 专属味道之dzw 掌柜昵称

is_tmall

Bool 0 false

post_fee

String 0 0.00 物流费用

area

String 0 广东 东莞 店铺所在地

detail_url

String 0 //item.taobao.com/item.htm?id=575727312808&ns=1#detail 宝贝链接

返回结果:

{
	"items": {
		"pagecount": 1,
		"total_results": 31,
		"real_total_results": 31,
		"item": [
			{
				"title": "成人专业压缩袜男蜂窝减震透气马拉松跑步袜女羽毛球袜击剑健身袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4//i3/121597573/O1CN01Y3G00p25oU6zjIK8h_!!2-saturn_solar.png",
				"promotion_price": "39",
				"price": "39",
				"sales": 10,
				"num_iid": "655779822509",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "南京",
				"detail_url": "//item.taobao.com/item.htm?id=655779822509",
				"cid": null
			},
			{
				"title": "袜子女春夏秋季女士毛巾底中筒袜吸湿透气纯棉运动篮球袜短袜女袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01RS0usy1KaUArb2hZI_!!1674221180.jpg",
				"promotion_price": "2.88",
				"price": "2.88",
				"sales": 2,
				"num_iid": "705555992925",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "石家庄",
				"detail_url": "//item.taobao.com/item.htm?id=705555992925",
				"cid": "50006846"
			},
			{
				"title": "男秋冬跑步篮球袜中筒高筒足球加厚毛巾底篮球袜子男运动袜中高筒",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01K4sl6P1R4bfbCoYjQ_!!1970922058.jpg",
				"promotion_price": "25",
				"price": "25",
				"sales": 0,
				"num_iid": "606054584068",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=606054584068",
				"cid": "50017261"
			},
			{
				"title": "sports socks, male ball socks, basketball socks, elite tow",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01SiqKiD1Er4pHSiary_!!3957300404.jpg",
				"promotion_price": "38",
				"price": "38",
				"sales": 0,
				"num_iid": "704728829643",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=704728829643",
				"cid": "50015374"
			},
			{
				"title": "高帮长筒专业加厚毛巾底透气防臭防滑男精英跑步健身运动袜篮球袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB1Fatcdfc3T1VjSZLeSuvZsVXa.jpg",
				"promotion_price": "8",
				"price": "8",
				"sales": 0,
				"num_iid": "637650981459",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "宁波",
				"detail_url": "//item.taobao.com/item.htm?id=637650981459",
				"cid": "50017261"
			},
			{
				"title": "10双新疆长绒棉篮球袜足球棉袜运动袜球粉吸汗防臭运动棉男女四季",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01KEe5dO1BzpYgPwqMF_!!2302260017.jpg",
				"promotion_price": "27.7",
				"price": "27.7",
				"sales": 0,
				"num_iid": "711294821305",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "南通",
				"detail_url": "//item.taobao.com/item.htm?id=711294821305",
				"cid": "50015374"
			},
			{
				"title": "实战篮球袜斗牛2.0专业中筒精英运动袜子加厚毛巾底男高帮运动袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN019Fdl471dsme8kaqjL_!!2861443792.jpg",
				"promotion_price": "18.8",
				"price": "18.8",
				"sales": 1,
				"num_iid": "677311368569",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "深圳",
				"detail_url": "//item.taobao.com/item.htm?id=677311368569",
				"cid": "50017261"
			},
			{
				"title": "专业跑步袜篮球袜户外运动袜加厚毛巾底中高筒四季防滑透气袜子男",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB2O.5xi_JYBeNjy1zeXXahzVXa_!!803549923.jpg",
				"promotion_price": "19.9",
				"price": "19.9",
				"sales": 0,
				"num_iid": "555678775418",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "杭州",
				"detail_url": "//item.taobao.com/item.htm?id=555678775418",
				"cid": "50015374"
			},
			{
				"title": "LINING  李宁 CBA 全明星 篮球袜  高帮 精英袜 舒适防滑运动袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01Jz5mQF1o6eihma0Ie_!!185365176.jpg",
				"promotion_price": "20",
				"price": "20",
				"sales": 0,
				"num_iid": "646462866460",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "揭阳",
				"detail_url": "//item.taobao.com/item.htm?id=646462866460",
				"cid": "50017261"
			},
			{
				"title": "JumpStart 拼色篮球精英袜 虎扑jrs推荐潮流拼多色缓压减震运动袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01euraYc2NMhEJkNhMo_!!2201506239949.jpg",
				"promotion_price": "29",
				"price": "29",
				"sales": 0,
				"num_iid": "679924181447",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "上海",
				"detail_url": "//item.taobao.com/item.htm?id=679924181447",
				"cid": "50015374"
			},
			{
				"title": "NBA精英袜紫金湖人队LA烫印24号 科比最后一战高筒加厚专业篮球袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01R5QdAt1bH6eceV2J3_!!3407973439.jpg",
				"promotion_price": "58",
				"price": "58",
				"sales": 0,
				"num_iid": "611958074443",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "衢州",
				"detail_url": "//item.taobao.com/item.htm?id=611958074443",
				"cid": "50017261"
			},
			{
				"title": "准者球员实战专业篮球球袜男中筒高帮防滑毛巾底精英跑步运动袜子",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01y3VC6p1TrHAWFHuIJ_!!2181532435.jpg",
				"promotion_price": "22.9",
				"price": "22.9",
				"sales": 10,
				"num_iid": "672482222538",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "泉州",
				"detail_url": "//item.taobao.com/item.htm?id=672482222538",
				"cid": "50017261"
			},
			{
				"title": "铠甲骑士篮球袜球星款男美式高帮长筒实战精英加厚毛巾袜运动袜子",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01sUB7HV1RMTMvZMOcm_!!623082097.jpg",
				"promotion_price": "13.8",
				"price": "13.8",
				"sales": 4,
				"num_iid": "680114015260",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "佛山",
				"detail_url": "//item.taobao.com/item.htm?id=680114015260",
				"cid": "50017261"
			},
			{
				"title": "专业精英篮球袜子户外运动毛巾底跑步袜男女长短筒防臭中筒加厚袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB24m9XuOMnBKNjSZFCXXX0KFXa_!!2235667460.jpg",
				"promotion_price": "16.9",
				"price": "16.9",
				"sales": 1,
				"num_iid": "571020092190",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=571020092190",
				"cid": "50017261"
			},
			{
				"title": "科比欧文加厚篮球袜精英运动袜子男中高筒防臭透气防滑吸汗毛巾底",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN014IlpOL26m1VPo3YrL_!!3547947703.jpg",
				"promotion_price": "17.9",
				"price": "17.9",
				"sales": 0,
				"num_iid": "613452964767",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=613452964767",
				"cid": "50017261"
			},
			{
				"title": "准者篮球球袜专业实战精英加厚防滑中筒高帮毛巾底跑步运动短长袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01NGwe1n1TrHC5SPoRP_!!2181532435.jpg",
				"promotion_price": "25.9",
				"price": "25.9",
				"sales": 825,
				"num_iid": "680792692267",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "泉州",
				"detail_url": "//item.taobao.com/item.htm?id=680792692267",
				"cid": "50017261"
			},
			{
				"title": "欧文詹姆斯科比精英篮球袜加厚毛巾底中高筒专业运动训练袜子潮男",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB29Cy0bCY9F1JjSZFFXXaBKXXa_!!2273019114.jpg",
				"promotion_price": "12.9",
				"price": "12.9",
				"sales": 0,
				"num_iid": "587437106235",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=587437106235",
				"cid": "50017261"
			},
			{
				"title": "斗牛实战篮球袜男中筒袜子毛巾底美式专业精英袜高帮跑步运动长袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN010Hlwzl1jI2czdOfjI_!!2214589004524.jpg",
				"promotion_price": "19.9",
				"price": "19.9",
				"sales": 0,
				"num_iid": "712455735288",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "绍兴",
				"detail_url": "//item.taobao.com/item.htm?id=712455735288",
				"cid": "50017261"
			},
			{
				"title": "准者袜男低帮短袜跑步运动袜中筒专业防滑篮球袜长筒袜加厚精英袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01tQO8LJ1TrH9mrHKMB_!!2181532435.jpg",
				"promotion_price": "10.9",
				"price": "10.9",
				"sales": 544,
				"num_iid": "556682941324",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "泉州",
				"detail_url": "//item.taobao.com/item.htm?id=556682941324",
				"cid": "50015374"
			},
			{
				"title": "SANHENG专业篮球飞盘运动中高筒厚底舒适透气防滑毛巾底精英球袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01cvYNSg2IvRETgxKjS_!!881809348.jpg",
				"promotion_price": "55",
				"price": "55",
				"sales": 0,
				"num_iid": "698468696477",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "泉州",
				"detail_url": "//item.taobao.com/item.htm?id=698468696477",
				"cid": "50017261"
			},
			{
				"title": "三恒专业篮球运动精英袜吸汗透气不臭脚耐磨不变形护踝包裹训练袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01T6rT2E25kMSKPNgun_!!1875647564.jpg",
				"promotion_price": "39",
				"price": "39",
				"sales": 1,
				"num_iid": "578664807025",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "泉州",
				"detail_url": "//item.taobao.com/item.htm?id=578664807025",
				"cid": "50017261"
			},
			{
				"title": "精英篮球袜短中筒高帮学生跑步袜男士防震加厚毛巾底专业运动袜子",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01RCbufw2K0J5dzA1GZ_!!2215904519494.jpg",
				"promotion_price": "13.8",
				"price": "13.8",
				"sales": 0,
				"num_iid": "719672901260",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "金华",
				"detail_url": "//item.taobao.com/item.htm?id=719672901260",
				"cid": "50006846"
			},
			{
				"title": "雄鹿队字母哥篮球袜男夏季高帮专业精英袜运动袜潮袜中长筒毛巾袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01nsv4bZ2Ap0V0Ufl6O_!!656628251.jpg",
				"promotion_price": "29.9",
				"price": "29.9",
				"sales": 0,
				"num_iid": "603925566146",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "广州",
				"detail_url": "//item.taobao.com/item.htm?id=603925566146",
				"cid": "50017261"
			},
			{
				"title": "NBA球员版stance篮球袜运动精英袜毛巾底实战加厚吸汗中高筒缓震",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01Aph1Us1yyNMv00M5R_!!2181686647.jpg",
				"promotion_price": "24",
				"price": "24",
				"sales": 0,
				"num_iid": "659528356583",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "绍兴",
				"detail_url": "//item.taobao.com/item.htm?id=659528356583",
				"cid": "50017261"
			},
			{
				"title": "一双起订球队个人专属个性文字图案号码加厚立体吸汗篮球袜定制",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01vBajVW1X42yRL7XzX_!!3182112869.jpg",
				"promotion_price": "15",
				"price": "15",
				"sales": 25,
				"num_iid": "615604968155",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "绍兴",
				"detail_url": "//item.taobao.com/item.htm?id=615604968155",
				"cid": "50017261"
			},
			{
				"title": "詹姆斯纯棉毛巾底精英袜加厚专业运动中筒吸汗防滑篮球训练袜子男",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB2Ueejd5RnpuFjSZFCXXX2DXXa_!!3003995184.jpg",
				"promotion_price": "22",
				"price": "22",
				"sales": 0,
				"num_iid": "544603032967",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "杭州",
				"detail_url": "//item.taobao.com/item.htm?id=544603032967",
				"cid": "50015374"
			},
			{
				"title": "实战专业篮球运动袜子毛巾底加厚精英男女高帮长筒训练美式跑步袜",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01oGkfTX1Jg9OT5Bbsu_!!3517301057.jpg",
				"promotion_price": "9.8",
				"price": "9.8",
				"sales": 0,
				"num_iid": "674241275454",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "绍兴",
				"detail_url": "//item.taobao.com/item.htm?id=674241275454",
				"cid": "50017261"
			},
			{
				"title": "韦德代言ST专业篮球袜加厚球员版赞助款篮球袜 精英袜无logo",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/TB2A02KopXXXXXgXFXXXXXXXXXX_!!351369262.jpg",
				"promotion_price": "15.8",
				"price": "15.8",
				"sales": 2,
				"num_iid": "543436341302",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "南通",
				"detail_url": "//item.taobao.com/item.htm?id=543436341302",
				"cid": "50017261"
			},
			{
				"title": "NBA球员版男子ST559库里篮球袜精英袜毛巾底加厚长筒运动休闲健身",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN011dFQE227EQ3LgKe10_!!2200589437765.jpg",
				"promotion_price": "39.96",
				"price": "39.96",
				"sales": 0,
				"num_iid": "723488515444",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "宁波",
				"detail_url": "//item.taobao.com/item.htm?id=723488515444",
				"cid": "50017261"
			},
			{
				"title": "包邮新款UA库里精英篮球袜加厚毛巾底健身运动中长筒吸汗透气防滑",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN01RJwnLf1JjoVFO79QC_!!866601065.jpg",
				"promotion_price": "24.7",
				"price": "24.7",
				"sales": 14,
				"num_iid": "650615172341",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "衢州",
				"detail_url": "//item.taobao.com/item.htm?id=650615172341",
				"cid": "50015374"
			},
			{
				"title": "篮球袜男高帮跑步运动实战美式训练长中筒专业精英毛巾底加厚袜子",
				"pic_url": "https://img.alicdn.com/img/bao/uploaded/i4/O1CN018U8l0q1SuCAFd1xW6_!!2215617062306.jpg",
				"promotion_price": "10.8",
				"price": "10.8",
				"sales": 584,
				"num_iid": "711657653032",
				"post_fee": null,
				"sample_id": "",
				"seller_nick": null,
				"is_tmall": "false",
				"area": "绍兴",
				"detail_url": "//item.taobao.com/item.htm?id=711657653032",
				"cid": "50017261"
			}

 

你可能感兴趣的:(电商api数据,java,python,开发语言)