https://www.thingclub.com/search?search=%E5%9C%9F%E5%A3%A4&thingType=PRODUCT
var pageSize = 24;
var searchKey = "土壤";
var arryAllHtml = [];
var pageStartIndex = 1;
GetData(pageStartIndex)
//console.log(arryAllHtml.join(""));
function GetData(pageIndex) {
var url = "https://www.thingclub.com/webapi/search/api/v2/search/search-things";
var data = { "isSku": true, "search": searchKey, "order": { "orderBy": "", "orderDirection": 1 }, "limit": pageSize, "page": pageIndex, "thingType": "PRODUCT", "queryFields": [], "options": [], "hardwareCompare": false, "structId": "", "excludedCompareIds": [], "e_keywordid": "" };
var xhr = new XMLHttpRequest();
//使用HTTP POST请求与服务器交互数据
xhr.open("POST", url, true);
//设置发送数据的请求格式
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
//根据服务器的响应内容格式处理响应结果
if (xhr.getResponseHeader('content-type').indexOf( 'application/json')>-1) {
var result = JSON.parse(xhr.responseText);
GetArryHtml(result.data);
console.log(pageStartIndex);
if (result.data.total > pageStartIndex * pageSize) {
pageStartIndex++;
GetData(pageStartIndex);
} else {
console.log(arryAllHtml.join(""));
}
} else {
console.log(xhr.getResponseHeader('content-type'));
//console.log(xhr.responseText);
}
}
}
//将用户输入值序列化成字符串
xhr.send(JSON.stringify(data));
}
function GetArryHtml(data) {
for (var i = 0; i < data.list.length; i++) {
var model = data.list[i];
var arryType = [];
if (model.tags) {
for (var index = 0; index < model.tags.length; index++) {
arryType.push(model.tags[index].name);
}
}
var info = { id: model.id, name: model.name, description: model.description, arryType: arryType.join(",") };
arryAllHtml.push(GetHtml((pageStartIndex-1) * pageSize+i+1, info))
}
}
function GetHtml(index, data) {
var html = '<p><span style = "font-family: 宋体, SimSun; font-size: 18px;" > <strong><span style="font-family: 宋体, SimSun; color: rgb(146, 208, 80); background-color: rgb(255, 255, 255);">' + index + '.' + data.name + '</span></strong></span >'
+ '</p ><p><span style="color: rgb(32, 33, 36); font-family: consolas, "lucida console", "courier new", monospace; background-color: rgb(255, 255, 255); font-size: 12px;">产品号:' + data.id + '</span>'
+ '</p><p> <span style="color: rgb(32, 33, 36); font-family: consolas, "lucida console", "courier new", monospace; font-size: 12px; background-color: rgb(255, 255, 255);">行业:<span style="font-family: consolas, "lucida console", "courier new", monospace; background-color: rgb(255, 255, 255); color: rgb(0, 176, 80); font-size: 16px;">' + data.arryType + '</span></span>'
+ '</p><p><span style="color: rgb(32, 33, 36); font-family: consolas, "lucida console", "courier new", monospace; font-size: 12px; background-color: rgb(255, 255, 255);display:block;">描述:' + data.description + '</span>'
+ '</p><p></p>';
return html;
}