1 Star 0 Fork 0

scientificworld / tieba-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
scientificworld 提交于 2022-02-05 00:20 . 1.0.0
var request = require('request').defaults({ jar: true });
j = request.jar();
class tieba {
constructor() {
var args = Array.prototype.slice.call(arguments);
if (args.length == 1) {
j.setCookie(request.cookie(`BDUSS=${args[0]}`), 'http://tieba.baidu.com');
} else {
throw new Error('failed to get user information');
}
}
tbs() {
return new Promise(function(resolve, reject) {
request({
url: 'http://tieba.baidu.com/dc/common/tbs',
jar: j
}, function(err, res, body) {
if (!err && res.statusCode == 200) {
resolve(JSON.parse(body)["tbs"]);
} else {
reject(err);
}
})
});
}
sign(bar) {
return this.tbs().then(function(msg) {
return new Promise(function(resolve, reject) {
request.post({
url: 'http://tieba.baidu.com/sign/add',
form: {
ie: 'utf-8',
kw: bar,
tbs: msg
},
jar: j
}, function(err, res, body) {
body = JSON.parse(body);
if (!err && res.statusCode == 200) {
if (body["no"] == 0)
resolve(body["data"]);
else
reject(body["error"]);
} else {
reject(err);
}
});
});
});
}
}
module.exports = tieba;
1
https://gitee.com/scientificworld/tieba-api.git
git@gitee.com:scientificworld/tieba-api.git
scientificworld
tieba-api
tieba-api
master

搜索帮助