mirror of
https://gitlab.com/moepoi/NekopoiScrapper.git
synced 2024-11-21 22:06:23 +01:00
Optimize getInfo
This commit is contained in:
parent
e4e8524b9c
commit
b7770e4483
1 changed files with 23 additions and 24 deletions
|
@ -7,30 +7,29 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
let links = [];
|
const getInfo = url => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const getInfo = (url) => {
|
axios.get(url)
|
||||||
return new Promise((resolve, reject) => {
|
.then(req => {
|
||||||
axios.get(url).then(function(req) {
|
try {
|
||||||
let soup = cheerio.load(req.data);
|
const links = [];
|
||||||
var title = soup("title").text();
|
let soup = cheerio.load(req.data);
|
||||||
soup('div.liner').each(function(i, e) {
|
let title = soup("title").text();
|
||||||
soup(e).find('div.listlink').each(function(j, s) {
|
soup('div.liner').each(function(i, e) {
|
||||||
links.push(soup(s).find('a').attr('href'))
|
soup(e).find('div.listlink').each(function(j, s) {
|
||||||
});
|
links.push(soup(s).find('a').attr('href'))
|
||||||
});
|
});
|
||||||
var data = {
|
});
|
||||||
"title": title,
|
const data = {
|
||||||
"links": links
|
"title": title,
|
||||||
};
|
"links": links
|
||||||
if (data == null) {
|
};
|
||||||
reject("No result :(");
|
resolve(data)
|
||||||
} else {
|
} catch (err) {
|
||||||
var result = JSON.stringify(data, null, 2);
|
reject('Error : ' + err)
|
||||||
resolve(result);
|
}
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = getInfo;
|
module.exports = getInfo;
|
Loading…
Reference in a new issue