Skip to content

Commit

Permalink
Merge pull request #233 from yfdyh000/20231120-CNKI
Browse files Browse the repository at this point in the history
fix(CNKI.js): 纠正POST表单数据,解决浏览器中抓取失败
  • Loading branch information
l0o0 committed Nov 20, 2023
2 parents 149cd29 + 589112b commit 495c77a
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions CNKI.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-11-19 13:57:30"
"lastUpdated": "2023-11-20 08:06:00"
}

/*
Expand Down Expand Up @@ -38,28 +38,22 @@ async function getRefWorksByID(id) {
var { dbname, filename, url } = id;
const postData = `FileName=${dbname}!${filename}!1!0&DisplayMode=Refworks&OrderParam=0&OrderType=desc&SelectField=&PageIndex=1&PageSize=20&language=&uniplatform=NZKPT&random=0.30585230060685187`;
const refer = `https://kns.cnki.net/dm/manage/export.html?filename=${dbname}!${filename}!1!0&displaymode=NEW&uniplatform=NZKPT`;
let reftext = await requestText(
'https://kns.cnki.net/dm/api/ShowExport',
let reftext = await request(
'https://kns.cnki.net/dm/api/ShowExport',
{
method: "POST",
body: postData,
responseType: "application/x-www-form-urlencoded",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Host": "kns.cnki.net",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
"Accept": "text/plain, */*; q=0.01",
"Accept-Language": "zh-CN,en-US;q=0.7,en;q=0.3",
"Accept-Encoding": "gzip, deflate, br",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": postData.length,
"Origin": "https://kns.cnki.net",
"Connection": "keep-alive",
"Referer": refer,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin"
"Referer": refer
}
});
}
);
if (reftext.status == 200) {
reftext = reftext.body
} else {
reftext = "CNKI.js: getRefWorksByID Error."
}
return reftext
.replace("<ul class='literature-list'><li>", "")
.replace("<br></li></ul>", "")
Expand Down

0 comments on commit 495c77a

Please sign in to comment.