Chrome浏览器先打开网页
--chrome控制台输入执行
const searchResult = []; const searchWord=encodeURI('四字词语');var next=true;var page=0; while(next) { var pn=(page-1)*100+100; await fetch('https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28204&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query='+searchWord+'&sort_key=&sort_type=1&stat0=&stat1=&stat2=&stat3=&pn='+pn+'&rn=100',{
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then((resp)=>{return resp.text()}).then((data)=>{ console.log(data);const datadata = JSON.parse(data); if(!datadata|| !datadata.data || !datadata.data[0] || !datadata.data[0].result || datadata.data[0].result.length <= 0){ next=false;return;} const result = datadata.data[0].result; page = page+1; Array.prototype.push.apply(searchResult, result);;})}; console.log(searchResult);
格式化代码
const searchResult = [];
const searchWord=encodeURI('四字词语');
var next=true;
var page=0;
while(next) {
var pn=(page-1)*100+100;
await fetch('https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28204&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query='+searchWord+'&sort_key=&sort_type=1&stat0=&stat1=&stat2=&stat3=&pn='+pn+'&rn=100',{
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then((resp)=>{return resp.text()
}).then((data)=>{
console.log(data);
const datadata = JSON.parse(data);
if(!datadata|| !datadata.data || !datadata.data[0] || !datadata.data[0].result || datadata.data[0].result.length <= 0){
next=false;return;
}
const result = datadata.data[0].result;
page = page+1;
Array.prototype.push.apply(searchResult, result);
}
)}
console.log(searchResult);
Blob下载html文件
const filename = '4word'; const csv= [] ; searchResult.forEach(row => {csv.push(row.ename+','+row.jumplink);});let csvFile = new Blob([csv.join('\n')], {type: 'text/csv'});let downloadLink = document.createElement('a');downloadLink.download = filename;downloadLink.href = window.URL.createObjectURL(csvFile);downloadLink.style.display = 'none'; document.body.appendChild(downloadLink);downloadLink.click()
const filename = '4word';
const csv= [] ;
searchResult.forEach(row => {csv.push(row.ename+','+row.jumplink);});
let csvFile = new Blob([csv.join('\n')], {type: 'text/csv'});
let downloadLink = document.createElement('a');
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click()
完整版(4字)
const searchResult = []; const searchWord=encodeURI('四字词语');var next=true;var page=0; while(next) { var pn=(page-1)*100+100; await fetch('https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28204&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query='+searchWord+'&sort_key=&sort_type=1&stat0=&stat1=&stat2=&stat3=&pn='+pn+'&rn=100',{
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then((resp)=>{return resp.text()}).then((data)=>{ console.log(data);const datadata = JSON.parse(data); if(!datadata|| !datadata.data || !datadata.data[0] || !datadata.data[0].result || datadata.data[0].result.length <= 0){ next=false;return;} const result = datadata.data[0].result; page = page+1; Array.prototype.push.apply(searchResult, result);;})}; console.log(searchResult);
const filename = '4word'; const csv= [] ; searchResult.forEach(row => {csv.push(row.ename+','+row.jumplink);});let csvFile = new Blob([csv.join('\n')], {type: 'text/csv'});let downloadLink = document.createElement('a');downloadLink.download = filename;downloadLink.href = window.URL.createObjectURL(csvFile);downloadLink.style.display = 'none'; document.body.appendChild(downloadLink);downloadLink.click()
完整版(5字)
const searchResult = []; const searchWord=encodeURI('五字词语');var next=true;var page=0; while(next) { var pn=(page-1)*100+100; await fetch('https://sp1.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28204&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query='+searchWord+'&sort_key=&sort_type=1&stat0=&stat1=&stat2=&stat3=&pn='+pn+'&rn=100',{
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then((resp)=>{return resp.text()}).then((data)=>{ console.log(data);const datadata = JSON.parse(data); if(!datadata|| !datadata.data || !datadata.data[0] || !datadata.data[0].result || datadata.data[0].result.length <= 0){ next=false;return;} const result = datadata.data[0].result; page = page+1; Array.prototype.push.apply(searchResult, result);;})}; console.log(searchResult);
const filename = '5word'; const csv= [] ; searchResult.forEach(row => {csv.push(row.ename+','+row.jumplink);});let csvFile = new Blob([csv.join('\n')], {type: 'text/csv'});let downloadLink = document.createElement('a');downloadLink.download = filename;downloadLink.href = window.URL.createObjectURL(csvFile);downloadLink.style.display = 'none'; document.body.appendChild(downloadLink);downloadLink.click()